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.

In C, what happens if you attempt to open a file for reading using fopen() but the file does not exist?

  • fopen() returns NULL, indicating that the file does not exist.
  • fopen() raises an exception.
  • fopen() creates a new file with the specified name.
  • fopen() prompts the user to enter the correct file name.
The correct option is "fopen() returns NULL, indicating that the file does not exist." If the file does not exist or cannot be opened for some reason, fopen() returns a NULL pointer, indicating an error in opening the file.

What function is used to open a binary file for both reading and writing in C?

  • fopen()
  • open()
  • openfile()
  • readfile()
In C, the fopen() function is used to open a binary file for both reading and writing. It returns a file pointer, which is essential for performing file operations.

Pointers can lead to ________ if not managed correctly in a C program.

  • Compilation errors
  • Memory leaks
  • Segmentation faults
  • Stack overflows
Pointers in C can cause segmentation faults when not handled properly. A segmentation fault occurs when a program tries to access memory that it's not allowed to access.

Function pointers in C can be passed as arguments to functions, thereby providing a degree of ________.

  • Abstraction
  • Encapsulation
  • Flexibility
  • Polymorphism
In C, function pointers enable polymorphism by allowing you to call different functions dynamically. This provides flexibility in your code.

What term is used to describe the process of calling a function within itself?

  • Casting
  • Looping
  • Recursion
  • Structuring
The process of calling a function within itself is known as "recursion." It allows for solving problems that can be broken down into smaller, similar subproblems.

The strlen function returns the length of a string, excluding the ________.

  • null terminator
  • first character
  • whitespace characters
  • special characters
The correct answer is the null terminator. The strlen function in C/C++ returns the length of a string by counting characters until it encounters the null terminator (''). It excludes the null terminator from the count. The other options are not what strlen excludes.

The C function ________ is used to compare two strings lexicographically.

  • strcmp
  • strncmp
  • strcompare
  • strcasecmp
The correct answer is strcmp. This function compares two strings character by character and returns an integer value representing their lexicographical order. strncmp is used for comparing a specific number of characters, and the other options are not valid C functions.