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.

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.

The ________ function is used to write data to a file in C.

  • fprintf
  • fread
  • fscanf
  • fwrite
In C, the fwrite function is used to write data to a file. It allows you to write binary data to a file stream.

Which standard library function in C is used to concatenate two strings?

  • strcat
  • strcmp
  • strconcat
  • strcopy
The strcat function in C is used to concatenate (append) one string to the end of another. It takes two strings as arguments and modifies the first string to include the second one at the end.

The use of ________ allows for dynamic memory allocation for arrays in C.

  • for loop
  • getchar()
  • malloc()
  • sizeof()
Dynamic memory allocation in C is achieved using functions like malloc().

How does the strtok() function work in C?

  • It calculates the length of a string
  • It converts a string to uppercase
  • It performs a binary search
  • It splits a string into multiple substrings based on a delimiter
The strtok() function in C is used to split a string into multiple substrings based on a specified delimiter. It maintains state between calls, making it useful for tokenizing strings.

What function can be used to find the current position of the file pointer in a file?

  • fseek()
  • readPosition()
  • getCurrentPointer()
  • filePosition()
The correct function to find the current position of the file pointer in a file is 'fseek()'. It allows you to set the file position indicator to a specific location in the file and returns the current position. The other options are not valid functions for this purpose.