What happens when realloc is called with a size parameter of zero?

  • It frees the previously allocated memory.
  • It leads to a memory leak.
  • It reallocates the memory with a size of zero.
  • It returns a null pointer.
When realloc is called with a size parameter of zero, it frees the previously allocated memory and returns a pointer to the freed memory, effectively deallocating it.

Which statement is true regarding the difference between inline functions and macros in C?

  • Inline functions can have local variables
  • Inline functions cannot be used with conditional compilation
  • Macros are preprocessed
  • Macros are type-safe
Macros in C are preprocessed, meaning they are replaced by their definitions before compilation. This can lead to unexpected behavior and debugging challenges. In contrast, inline functions are compiled as proper functions with type safety and can have local variables.

An array of structures can be used to represent a collection of ________ that share the same attributes but have different values.

  • Constants
  • Functions
  • Objects
  • Variables
Arrays of structures in C are commonly used to represent a collection of objects (or variables) that share the same attributes but have different values, making them an efficient way to manage related data.

How does a double pointer differ from a single pointer?

  • Can store multiple values
  • Points to a memory address
  • Points to another pointer
  • Stores double the data
A double pointer in C points to the memory address of a pointer, while a single pointer points to a single memory address. It allows for indirection, which can be useful in certain scenarios.

You are developing a program to manage the seating arrangement in a movie theater with rows and columns. How would you represent the seats using arrays?

  • 1D Array
  • 2D Array
  • Linked List
  • Queue (FIFO)
Seats in a theater can be efficiently represented using a 2D array, with rows and columns, making it easy to access and manage each seat's status.

How does the 'return' statement affect the flow of control within a loop?

  • The 'return' statement exits the loop, returning control to the calling function or method.
  • The 'return' statement has no impact on the flow of control within a loop.
  • The 'return' statement skips the next iteration of the loop.
  • The 'return' statement terminates the entire program when used within a loop.
The 'return' statement is used to exit a function or method prematurely and return a value. When a 'return' statement is encountered within a loop, it immediately exits the loop and returns control to the calling function or method. This can be useful for ending a loop under certain conditions or returning a value from the loop.

When using dynamic memory allocation for arrays, which standard library function is used to release the memory that was previously reserved?

  • calloc
  • free
  • malloc
  • realloc
The correct function to release dynamically allocated memory is free. It is used to deallocate the memory previously reserved using malloc or calloc.

The function ________ is used to find the first occurrence of a character in a string in C.

  • findchar
  • locatechar
  • strchr
  • searchchar
The correct answer is strchr. strchr is a standard C function used to find the first occurrence of a character in a string. The other options are not valid C functions for this purpose.

What is the primary purpose of the malloc function in C?

  • To allocate memory for a single variable
  • To allocate memory for an array of elements and initialize them
  • To free memory allocated by calloc
  • To reallocate memory for an array
The primary purpose of the malloc function in C is to allocate memory for a single variable. It returns a pointer to the allocated memory, which can be used to store data.

When reading a file in C, which function can be used to check if the end of the file has been reached?

  • fclose()
  • feof()
  • ferror()
  • fseek()
The feof() function is used to check if the end of a file has been reached during file reading operations in C.