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.

How are strings typically terminated in C?

  • With a comma
  • With a newline character
  • With a null character ( '' )
  • With a space character
Strings in C are typically terminated with a null character ('') to indicate the end of the string.

In a program that processes large datasets, you notice that reading the data from a file is a performance bottleneck. Which file handling functions could help improve the performance?

  • fread() and fwrite()
  • fseek() and ftell()
  • fprintf() and fscanf()
  • fgetc() and fputc()
To improve performance when dealing with large datasets, using fread() and fwrite() for bulk reading and writing of data would be beneficial. The other options involve more granular or formatted I/O operations.

What is the difference between #include "filename" and #include in C?

  • #include "filename" is for standard library files.
  • #include "filename" is for user-defined files.
  • #include is for user-defined files.
  • They are interchangeable and have no difference.
In C, #include "filename" is used for user-defined header files, and #include is used for standard library header files.

Which searching algorithm is typically the most straightforward to implement?

  • Binary search
  • Hash table
  • Jump search
  • Linear search
Linear search is the most straightforward searching algorithm as it involves a simple step-by-step comparison of elements in the array.

What is the advantage of using pointers to structures instead of directly using structures?

  • Easier debugging
  • Enhanced code readability
  • Faster access to data
  • Improved memory management
Using pointers to structures allows for improved memory management by reducing memory wastage. When a structure is passed as a function argument, it is copied, leading to extra memory usage. Pointers avoid this issue.

In C, a ________ is used to store a sequence of characters.

  • array
  • function
  • string
  • variable
In C, a 'string' is used to store a sequence of characters. A string is an array of characters, typically represented as an array of 'char' data type.