In a C program, you notice that data written to a file is not immediately visible on the disk. What could be a reason for this delay?

  • Buffering
  • File format mismatch
  • File permissions issue
  • Insufficient disk space
Buffering is a common reason for a delay in writing data to a file in C. The system may buffer data before writing it to disk for efficiency. This buffering can cause a delay in making the data visible on the disk.

What is the lifetime of a static variable in a C program?

  • Limited to the function it's defined in
  • Same as the program's runtime
  • Until the function exits
  • Until the program exits
The lifetime of a static variable in C is the same as the program's runtime. It retains its value between function calls and persists until the program terminates.

Double pointers are often used in C to create a(n) ________ of pointers.

  • Array
  • Array of Pointers
  • List
  • Structure
Double pointers in C are often used to create an array of pointers, allowing you to work with multiple pointers efficiently.

You're tasked with optimizing a program that reads large text files. What strategies could you employ to improve the performance of the file reading operation?

  • Employ memory-mapped files to reduce I/O operations.
  • Ignore error handling to reduce overhead.
  • Read the entire file into memory at once.
  • Use a simple sequential read operation without any optimizations.
Utilizing memory-mapped files can reduce I/O operations and improve the performance of reading large text files. Loading the entire file into memory can lead to resource issues.

The members of a structure are accessed using the ________ operator.

  • -> (arrow)
  • . (dot)
  • :: (scope)
  • [] (brackets)
In C, members of a structure are accessed using the dot (.) operator.

In a project involving real-time systems, you notice that different modules use different naming conventions for the same data type. What feature of C can help maintain consistency across modules?

  • Typedef
  • Namespaces
  • Code comments
  • Function pointers
Option A, "Typedef," is the most suitable choice in this context. By using typedef, you can create consistent, user-friendly names for data types, which helps maintain a unified naming convention across modules in a project. This consistency enhances code readability, reduces errors, and simplifies maintenance. Namespaces are not a feature in C, and other options do not directly address naming convention consistency. Understanding how to use typedef effectively is essential for creating a consistent codebase in C.

How can you redirect error messages in a C program to a file instead of displaying them on the console?

  • stderr_redirect()
  • errorToFile()
  • file_error()
  • freopen()
The correct option is freopen(). This function can be used to redirect standard error (stderr) to a file. By using freopen("error.log", "w", stderr), error messages will be written to the specified file instead of the console.

In C, pointers can be used to pass ________ to a function.

  • addresses
  • constants
  • data
  • variables
In C, pointers can be used to pass addresses to a function. This allows functions to modify the original data.

Which preprocessor directive is used to include a header file in a C program?

  • #define
  • #ifdef
  • #ifndef
  • #include
The preprocessor directive #include is used to include a header file in a C program. It allows you to use functions and declarations from the included file in your program.

In a database application, you need to sort a list of names (strings) in alphabetical order. Which string handling function might be useful in this scenario?

  • strchr
  • strcmp
  • strnlen
  • strtok
To sort a list of names in alphabetical order, the strcmp function is useful. It compares two strings and returns a value indicating their relative order. strtok is used for tokenizing strings, strchr searches for a character in a string, and strnlen provides the length of a string up to a specified limit.