The ________ directive is used to define symbolic names or constants in a C program.

  • #constant
  • #define
  • #enum
  • #import
The correct answer is (b) #define. In C, the #define preprocessor directive is used to define symbolic names or constants. These names can simplify your code and make it more readable.

How does the execution stack change when a recursive function is called in C?

  • A new thread is created
  • Each function call adds a new stack frame
  • The stack remains unchanged
  • The stack shrinks
In C, when a recursive function is called, each function call adds a new stack frame to the execution stack. These stack frames store the local variables and return addresses for each function call. This process continues until the base case is reached.

In a graphics program, you need to define colors where each color can be represented as either a name or an RGB triplet. How would you efficiently represent this in C?

  • Using a function
  • Using a structure
  • Using a union
  • Using an enum
In C, a union would efficiently represent colors that can be either a name or an RGB triplet because it allows sharing the same memory location for different data types. Enums, structures, and functions are not suitable for this purpose.

To check for errors during file operations, you can use the ______ function.

  • fileStatus()
  • checkFileError()
  • feof()
  • ferror()
The correct option is d) ferror(). This function is used to check for errors during file operations and returns a non-zero value if an error is encountered.

What is the primary purpose of using typedef in C programming?

  • Creating a new data type
  • Declaring global variables
  • Defining variables within a structure using bit fields
  • Managing memory allocation
Typedef in C is used for creating aliases or alternative names for existing data types. It simplifies code, improves code readability, and enhances portability by allowing you to use more meaningful names for data types.

For efficient memory utilization in dynamic arrays, it is important to release the allocated memory using the function _________.

  • free()
  • malloc()
  • realloc()
  • calloc()
The correct option is 'free()'. It is essential to use the free() function to release dynamically allocated memory to avoid memory leaks.

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.

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.

What is the purpose of the 'switch' statement in C?

  • To perform iterative loops
  • To handle exceptions
  • To provide multiple choices
  • To enhance code readability
The 'switch' statement in C is used to provide multiple choices based on the value of an expression. It allows for a concise way to write code when there are multiple possible execution paths. Each 'case' represents a different possible value of the expression, improving code readability and maintainability, especially when dealing with menu-driven programs or handling different options.

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.