How can you open a file for both reading and writing in C?

  • fopen("file.txt", "rw")
  • fopen("file.txt", "r+")
  • fopen("file.txt", "w+")
  • open("file.txt", "rw")
The correct option is b. fopen("file.txt", "r+"). This combination of mode flags in the fopen() function allows a file to be opened for both reading and writing, providing flexibility in file manipulation operations.

When is it appropriate to use the free function in C programming?

  • After allocating memory using malloc
  • At the beginning of your program
  • When you are done using dynamically allocated memory
  • Whenever you want
The free function in C is used to deallocate the dynamically allocated memory when you are done using it. It helps prevent memory leaks and frees up resources.

What is the significance of the return type in a function declaration in C?

  • It defines the scope of variables used within the function
  • It determines the function's execution order
  • It indicates the data type of the value the function returns
  • It specifies the number of arguments a function can take
The return type in a function declaration in C indicates the data type of the value that the function will return to the calling program. This information is vital for using the function correctly and processing its result.

In a two-dimensional array declared as int arr[5][10];, the expression arr[i][j] refers to the ________ element in memory.

  • i-th column, j-th row
  • i-th row, j-th column
  • j-th column, i-th row
  • j-th row, i-th column
In a two-dimensional array, the first index corresponds to rows, and the second index corresponds to columns. So, arr[i][j] refers to the element at the i-th row and j-th column.

What is the difference between stderr and stdout in the context of buffering?

  • stderr is unbuffered, while stdout is line-buffered by default.
  • stderr is line-buffered, while stdout is unbuffered.
  • stderr is fully buffered, while stdout is line-buffered.
  • stderr is fully buffered, while stdout is unbuffered.
The correct option is "stderr is unbuffered, while stdout is line-buffered by default." stderr is typically unbuffered, meaning that data is immediately written to the output, while stdout is line-buffered, meaning that it is buffered until a newline character is encountered.

You are working on a program that processes large datasets. Why might you choose to use pointers and pointer arithmetic to traverse the data?

  • To enable dynamic data structures
  • To enhance data access speed
  • To improve memory efficiency
  • To simplify code readability
Using pointers and pointer arithmetic can significantly improve data access speed. It allows direct memory access, reducing the need for complex data structures and enhancing performance in large dataset processing.

Which keyword is used in C to create an alias for a data type?

  • enum
  • struct
  • typedef
  • union
In C programming, the "typedef" keyword is used to create an alias or a new name for an existing data type. This makes the code more readable and can help in achieving better code organization.

The preprocessor directive ________ is used to include libraries in a C program.

  • #define
  • #ifdef
  • #include
  • #pragma
The correct answer is (b) #include. In C, the #include preprocessor directive is used to include libraries or header files. This allows you to use functions and definitions from those libraries in your program.

In C, the ________ function is used to write a string to a file.

  • write()
  • fputstring()
  • fwrite()
  • fputs()
The correct option is fputs(). This function is used to write a string to a file in C, providing a convenient way to output a sequence of characters to the specified file.

How can you determine the size of an array in C?

  • By counting the number of elements
  • By using the 'size' function
  • Using the 'length' keyword
  • Using the 'sizeof' operator
You can determine the size of an array in C by using the 'sizeof' operator. It returns the size in bytes, so dividing it by the size of one element gives you the number of elements in the array.