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.

When using pointers in a C program, what does the 'dereferencing' operation do?

  • Accesses the value stored at a memory address
  • Allocates memory for a new pointer
  • Increases the pointer's size
  • Retrieves the memory address of a variable
Dereferencing a pointer in C means accessing the value stored at the memory location pointed to by the pointer. It allows you to work with the actual data.

What is the purpose of the strcpy function in C?

  • Allocates memory for a new string
  • Calculates the length of a string
  • Compares two strings
  • Copies one string to another
The strcpy function in C is used to copy one string into another. It does not calculate the length, compare strings, or allocate memory.