When declaring a variable in C, what does the 'static' keyword do to the variable's lifetime?

  • Doesn't affect it
  • Extends it
  • Initializes it
  • Shortens it
The 'static' keyword in C extends the lifetime of a variable, allowing it to retain its value between function calls, making it suitable for data that persists.

What is the time complexity of the bubble sort algorithm in the best case?

  • O(1)
  • O(log n)
  • O(n)
  • O(n^2)
The best-case time complexity of the bubble sort algorithm is O(n) when the array is already sorted, and no swaps are required during the pass.

When would it be beneficial to use a function pointer instead of a direct function call?

  • Dynamically choosing a function to execute
  • Enhancing compile-time error checking
  • Reducing code complexity
  • Simplifying code structure
Using a function pointer is beneficial when you need to dynamically choose a function to execute at runtime. It offers flexibility and is useful in various scenarios.

Which function is used to close a file that has been opened using fopen?

  • fclose
  • fopen
  • fread
  • fwrite
The fclose function is used to close a file that has been opened using fopen. This is important to release system resources and ensure data is properly saved.

What is the primary purpose of using pointers in a C function?

  • To allocate memory dynamically
  • To execute loops
  • To perform arithmetic operations
  • To store character data
Pointers in C allow you to allocate memory dynamically. They are often used to work with data structures, dynamic memory allocation, and creating flexible functions.

You are developing an application that needs to represent a value that could either be an integer or a floating-point number. How could you efficiently represent this data using C?

  • Using a linked list
  • Using a structure
  • Using a union
  • Using an array
In C, a union allows you to efficiently represent data that can be either an integer or a floating-point number, as it allows sharing the same memory location for different data types. Arrays, structures, and linked lists are not suitable for this purpose.

Using a union can lead to efficient memory usage when you need to store different ________ at different times.

  • data types
  • members
  • structures
  • values
When you use a union, you can store different data types in the same memory location, depending on the specific member you access. This can help save memory when you need to handle various types of data at different times.

In C programming, what is tail recursion?

  • A recursion that involves a loop
  • A recursion with a base case at the beginning
  • A recursion with a base case at the end
  • A recursion with no base case
Tail recursion in C is a type of recursion where the base case is located at the end of the recursive function. This means that the recursive call is the last operation in the function, making it more efficient and easier for the compiler to optimize.

An array of structures in C allows you to store multiple records, where each record can have ________ of different data types.

  • Elements
  • Fields
  • Files
  • Functions
An array of structures allows you to store multiple records, where each record can have fields of different data types. Fields represent the individual members of each structure.

You are tasked with optimizing a C program that manipulates large strings. What standard library functions might be critical to review for potential performance bottlenecks?

  • getchar() and putchar()
  • malloc() and free()
  • printf() and scanf()
  • strlen() and strcat()
When optimizing a C program that manipulates large strings, functions like strlen() and strcat() should be reviewed for potential performance bottlenecks as they involve string manipulation and can be resource-intensive.

How can you specify the starting value of an enumeration in C?

  • By initializing the first element of the enumeration with a value
  • By using the sizeof operator
  • It's not possible to specify the starting value
  • Using the #define directive
In C, you can specify the starting value of an enumeration by initializing the first element with a value. This value will be the starting point, and subsequent elements will increment from there.

You need to implement a function that modifies multiple variables of different data types. What concept related to pointers would you use?

  • Arrays of pointers
  • Function pointers
  • Generic pointers
  • Typecasting pointers
Typecasting pointers would allow you to change the data type of a pointer to manipulate variables of different data types in a single function.