In optimizing a recursive algorithm for calculating Fibonacci numbers, what concept can be applied to avoid redundant calculations?

  • Dynamic Typing
  • Functional Programming
  • Memoization
  • Object-Oriented Programming
Memoization is the concept that can be applied to store and reuse intermediate results, avoiding redundant calculations and significantly improving the efficiency of the algorithm.

What is a double pointer in C?

  • It is a pointer that cannot be modified
  • It is a pointer that has two asterisks **
  • It is a pointer that points to floating-point numbers
  • It is a pointer that points to two different memory locations
A double pointer in C is represented with two asterisks ** and is used to point to another pointer. It allows you to modify the pointer it is referencing.

When a file is opened in 'w' mode using fopen, if the file already exists, its contents are ________.

  • Overwritten
  • Appended
  • Preserved
  • Erased
In 'w' mode, if the file already exists, its contents are overwritten, so option a) "Overwritten" is the correct answer.

How does the compiler determine the size of a structure containing bit fields?

  • It uses a fixed size for all structures
  • It sums the sizes of individual bit fields
  • It calculates based on the alignment requirements
  • It uses a predetermined value
The correct option is c) It calculates based on the alignment requirements. When a structure contains bit fields, the compiler determines the size of the structure based on the alignment requirements of the platform. It may add padding bits to ensure proper alignment, which affects the overall size of the structure.

In C, a string is essentially an array of ________ terminated by a null character.

  • characters
  • floats
  • integers
  • pointers
In C, a string is essentially an array of characters terminated by a null character (''). This null character signifies the end of the string and is used to differentiate between the end of one string and the beginning of another in memory.

In C, the base address of an array arr can be accessed using ________.

  • &arr
  • &arr[0]
  • arr
  • arr[0]
To access the base address of an array in C, you can simply use the array name without an index, which is equivalent to &arr[0]. So, both &arr and arr[0] provide the base address.

You're developing a program that needs to behave differently based on user input provided at runtime. How can command line arguments be utilized for this purpose?

  • By using the 'if-else' statements
  • By using environment variables
  • By reading input from a file
  • By utilizing command line arguments
Command line arguments allow a program to receive input from the user at runtime, typically provided when the program is executed from the command line. This input can be used to control the program's behavior. Options a, b, and c are not typically used for this specific purpose.

You are tasked with creating an easy-to-read API for a library written in C. What feature can you use to make the data types and function signatures more user-friendly?

  • Typedef
  • Global variables
  • Preprocessor macros
  • Volatile keyword
Option A, "Typedef," is the appropriate choice. Typedef allows you to create custom, user-friendly names for data types, improving the readability of your API. It helps in abstracting complex data structures and makes the code more intuitive for users of the library. Global variables, preprocessor macros, and the volatile keyword are not directly related to improving API readability and can introduce issues with maintainability and understandability. Understanding typedef is crucial for designing user-friendly APIs in C.

What is a key advantage of using a sorted array over an unsorted array?

  • Easier insertion of elements
  • Faster searching
  • Lower memory usage
  • Random access
A key advantage of a sorted array is faster searching using techniques like binary search, which has a logarithmic time complexity.

What is the primary disadvantage of using dynamic memory allocation for arrays in C?

  • Fragmentation
  • Inefficiency
  • Limited Size
  • Slow Access
Dynamic Memory Allocation can lead to memory fragmentation, which can waste memory and affect program performance.