What would be the result of trying to access an array with a pointer that has not been initialized?

  • It will access a random memory location, leading to undefined behavior.
  • The pointer will point to the beginning of the array.
  • The program will compile but throw a runtime error.
  • The program will not compile.
Accessing an array with an uninitialized pointer in C leads to undefined behavior because the pointer doesn't point to a valid memory location. The result is unpredictable and can lead to crashes or incorrect data manipulation.

When declaring a string literal in C, which character is automatically appended at the end?

  • Exclamation mark '!'
  • Null terminator ''
  • Question mark '?'
  • Semicolon ';'
In C, a null terminator '' is automatically appended at the end of a string literal. This null character indicates the end of the string, allowing C functions to determine the string's length.

When passing an array to a function in C, what is actually being passed?

  • A pointer to the first element
  • The entire array
  • The size of the array
  • The value of the first element in the array
In C, when passing an array to a function, only a pointer to the first element is passed, allowing the function to access the entire array.

When opening a file with fopen, what happens if the file does not exist and the mode is set to 'r'?

  • It appends data to the existing file.
  • It creates a new file.
  • It overwrites the file's content.
  • It returns a NULL pointer.
When opening a file with fopen in read mode ('r') and the file doesn't exist, it returns a NULL pointer, indicating that the file was not successfully opened.

An enumeration is a user-defined data type that consists of integral ________.

  • Characters
  • Functions
  • Pointers
  • Values
An enumeration is a user-defined data type that consists of integral values, typically used for defining a set of named integer constants.

The ________ algorithm is known for its simplicity but is inefficient for sorting large datasets.

  • Bubble Sort
  • Merge Sort
  • Quick Sort
  • Selection Sort
The correct option is 'Bubble Sort'. While Bubble Sort is easy to understand, it is not efficient for large datasets due to its O(n^2) time complexity.

A two-dimensional array can be visualized as a ________.

  • Linked List
  • One-dimensional array
  • Table
  • Tree Structure
A two-dimensional array can be visualized as a table with rows and columns.

When defining a bit field, what does the number after the colon represent?

  • Bit order
  • Bit position
  • Bit size
  • Bit value
The number after the colon represents the bit size, indicating how many bits the bit field can occupy.

What is the main difference between function declaration and function definition in C?

  • Declarations contain the function's code
  • Declarations specify the function's name
  • Definitions declare the function's return type
  • Definitions provide the function's implementation
The main difference between function declaration and function definition in C is that declarations specify the function's name and data types, while definitions provide the actual implementation of the function.

Command line arguments are accessed in a C program using the parameters ________ and ________ in the main function.

  • argc, argv
  • input, output
  • param1, param2
  • source, target
The correct answer is (a) argc, argv. In C, the main function can take two parameters: argc, which represents the number of command-line arguments, and argv, which is an array of strings containing those arguments.

The memory consumed by an array declared as float arr[10][20]; is ________.

  • 2000 bytes
  • 400 bytes
  • 80 bytes
  • 800 bytes
The memory consumed by a two-dimensional array is calculated by multiplying the number of rows by the number of columns and then multiplying it by the size of the data type. In this case, it's 10 (rows) * 20 (columns) * 4 bytes (float) = 800 bytes.

In C, subtracting two pointers that point to elements of the same array yields a result of type ________.

  • double
  • int
  • ptrdiff_t
  • size_t
In C, subtracting two pointers that point to elements of the same array yields a result of type ptrdiff_t. This type represents the signed integral difference between the two pointers. It's important to use ptrdiff_t when performing pointer subtraction to ensure portability and accurate results, especially in situations involving pointer arithmetic.