How does the 'extern' keyword affect the scope and lifetime of a variable in C?

  • It doesn't affect the scope or lifetime of a variable.
  • It extends the scope and lifetime of a variable.
  • It extends the scope but reduces the lifetime of a variable.
  • It reduces the scope but extends the lifetime of a variable.
In C, the 'extern' keyword extends the scope of a variable but reduces its lifetime. It allows a variable declared outside a function to be used within that function, but the variable's lifetime remains outside the function.

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.

What is a potential drawback of using bit fields in a cross-platform application?

  • Inefficient memory usage
  • Lack of platform portability
  • Compiler-specific behavior
  • Slower execution
The correct option is c) Compiler-specific behavior. Using bit fields in a cross-platform application can lead to issues due to compiler-specific behavior. Different compilers may interpret bit fields differently, causing inconsistencies across platforms.

Which function would you use to compare two strings lexicographically in C?

  • strcat()
  • strcmp()
  • strcpy()
  • strlen()
You would use the strcmp() function to compare two strings lexicographically in C. It returns 0 if the strings are equal, a positive value if the first string is greater, and a negative value if the second string is greater.

Using the ________ function, the file pointer can be moved to the end of a file.

  • fseek()
  • rewind()
  • ftell()
  • fsetpos()
The correct option is fseek(). This function is used to set the file position indicator to a specific position within the file. When the SEEK_END constant is provided as the reference point, it moves the file pointer to the end of the file, allowing operations like appending data.