In C programming, why would you use an enumeration (enum)?

  • To create multi-dimensional arrays
  • To define a set of named integer constants
  • To perform arithmetic operations
  • To store floating-point numbers
Enumerations (enums) in C are used to define a set of named integer constants, making your code more readable and self-explanatory.

How can function pointers be used to implement callbacks in C?

  • Function pointers allow direct function calls
  • Function pointers are not suitable for callbacks
  • Function pointers are only used for dynamic memory allocation
  • Function pointers can be passed as arguments to other functions
Function pointers in C can be passed as arguments to other functions, allowing you to define callbacks. This is commonly used in event-driven programming and implementing libraries with customizable behavior.

How do you declare a two-dimensional array of integers with 3 rows and 4 columns?

  • int arr[12];
  • int arr[3][4];
  • int arr[4][3];
  • int arr[][];
To declare a 2D array in C with 3 rows and 4 columns, you use the syntax: int arr[3][4]; The first dimension specifies the number of rows, and the second dimension specifies the number of columns.

In the context of C programming, what is the importance of having a base case in a recursive function?

  • It makes the program run faster
  • It prevents infinite recursion and stack overflow
  • It reduces the need for using pointers
  • It simplifies the program's overall structure
Having a base case in a recursive function is crucial to prevent infinite recursion, which can lead to a stack overflow and program termination. The base case provides a stopping condition for the recursion and ensures the function terminates properly.

What is the purpose of the 'break' statement within a loop?

  • Continue to the next iteration
  • Exit the loop
  • Print a message
  • Skip the current iteration
The 'break' statement is used to exit a loop prematurely. When encountered, it terminates the loop and continues with the next code after the loop.

When defining a bit field, the data type ________ is typically used.

  • char
  • double
  • float
  • int
When defining a bit field in C, the char data type is typically used, as it allows for better control over the number of bits allocated to the field.

When dealing with large files, what is the advantage of using fread and fwrite over fscanf and fprintf?

  • fread and fwrite allow block-level operations.
  • fscanf and fprintf are more efficient for large files.
  • fread and fwrite provide better error handling.
  • fscanf and fprintf simplify binary file handling.
The correct option is fread and fwrite allow block-level operations. Using these functions, data can be read or written in larger chunks, reducing the number of I/O operations and improving performance when dealing with large files in C.

How can command line arguments be used to influence the flow of a program at runtime?

  • By modifying the source code of the program.
  • By passing arguments when the program is executed.
  • By using conditional statements in the program.
  • By using preprocessor directives in the code.
Command line arguments are parameters passed to a program when it's executed, allowing you to influence the program's behavior at runtime.

In the context of function pointers in C, a callback function is a function that is passed as a(n) ________ to another function.

  • Argument
  • Parameter
  • Pointer
  • Variable
In C, a callback function is passed as a parameter to another function, allowing the function to call back to the provided function.

What happens if you try to modify a character in a string literal?

  • It converts the string to uppercase
  • It is allowed and won't cause any issues
  • It raises a compile-time error
  • It raises a run-time error
Modifying a character in a string literal is not allowed because string literals are stored in read-only memory, and attempting to modify them will result in a compile-time error.