You are developing an interactive application that continuously accepts user input until the user decides to exit. Which loop construct would be most appropriate for this scenario?

  • do-while loop
  • for loop
  • switch statement
  • while loop
The most appropriate loop construct for an interactive application that accepts user input until the user decides to exit is a 'while loop.' It allows continuous input acceptance while checking an exit condition.

In C, when an array is passed to a function, is it passed by value or by reference?

  • By reference
  • By value
  • It depends on the array size
  • Not possible to pass arrays to functions
In C, arrays are passed to functions by reference, which means that changes made to the array inside the function affect the original array in the caller.

What is the primary cause of memory leaks in a C program?

  • Excessive memory fragmentation.
  • Failure to free dynamically allocated memory.
  • Incorrect use of the malloc function.
  • Insufficient memory allocation.
The primary cause of memory leaks in a C program is the failure to free dynamically allocated memory using functions like free(). When you allocate memory but don't deallocate it properly, it leads to memory leaks.

What is the scope of a global variable in a C program?

  • Accessible throughout the entire program
  • Limited to the file where it's declared
  • Local to the function it's defined in
  • Only within the main() function
In C, global variables have a scope that spans the entire program, meaning they can be accessed from any part of the code.

When a string is declared as a character array, the string must be terminated with a ________.

  • comma
  • null character
  • semicolon
  • space
In C, a string is a sequence of characters terminated by a null character (''). This null character signifies the end of the string.

What is the result of comparing two strings using the '==' operator in C?

  • It compares the ASCII values of the first characters
  • It compares the content of the strings
  • It compares the length of the strings
  • It compares the memory addresses of the strings
In C, the '==' operator compares the memory addresses of the strings, not their content.

In a program that processes large amounts of data, what strategy can be used to optimize the performance of loops?

  • Loop branching optimization
  • Loop indexing optimization
  • Loop parallelization
  • Loop unrolling
To optimize the performance of loops when processing large data, 'loop unrolling' can be used. Loop unrolling reduces loop overhead and can improve data processing speed.

The fread function in C is used to read data from a file and stores the data in the ________.

  • Buffer
  • Memory
  • Stack
  • Registers
The fread function in C reads data from a file and stores it in memory, making option b) "Memory" the correct answer.

In C, the ________ function is used to copy a specified number of characters from one string to another.

  • memcpy()
  • strcpy()
  • strncat()
  • strncpy()
In C, the strncpy() function is used to copy a specified number of characters from one string to another. Unlike strcpy(), it allows you to specify the maximum number of characters to copy, which helps prevent buffer overflows and enhances program security.

In C, a double pointer is a pointer that points to another ________.

  • double
  • int
  • pointer
  • variable
In C, a double pointer is a pointer that points to another pointer. It is used to store the address of a pointer variable.