A ________ search works by repeatedly dividing the portion of the array that could contain the item until you've narrowed down the possible locations to just one.
- Binary
- Depth-First
- Hash
- Linear
A 'Binary' search works by repeatedly dividing the portion of the array that could contain the item until you've narrowed down the possible locations to just one. It's an efficient search algorithm for sorted arrays.
How does the 'ternary' operator (?:) work in C?
- It defines a function in C
- It performs bit-level operations
- It's used for binary arithmetic
- It's used to create a conditional expression
The 'ternary' operator in C, represented as '?:', is a shorthand way to write a simple conditional expression. It allows you to return one of two values based on a condition.
What is a key characteristic of a union in C?
- Allows multiple data types in a single memory location
- Automatically allocates memory on the stack
- Only works with integers
- Provides dynamic memory allocation
A union in C allows you to store different data types in a single memory location, and it's a crucial feature for creating composite data types.
In C, which function can be used to search for a substring within a string?
- find()
- locate()
- search()
- strstr()
The strstr() function in C is used to search for a substring within a string. It returns a pointer to the first occurrence of the substring or NULL if the substring is not found.
How does the 'switch' statement compare to a series of 'if-else' statements in terms of efficiency?
- The 'switch' statement is generally more efficient when comparing a single value to multiple options.
- The 'switch' statement is less efficient than 'if-else' statements.
- The 'switch' statement and 'if-else' statements have the same efficiency.
- Efficiency depends on the specific use case.
The 'switch' statement is typically more efficient than a series of 'if-else' statements when you need to compare a single value to multiple options. It allows for jump tables, which can lead to faster execution. However, the efficiency may vary depending on the compiler and specific scenarios.
In C++, if two overloaded functions have the same signature but differ in const qualification, it leads to ________.
- Ambiguity Error
- Compilation Error
- Linker Error
- Undefined Behavior
When two overloaded functions in C++ have the same signature but differ in const qualification, it leads to undefined behavior. The compiler cannot determine which function to call, resulting in ambiguous code. It's essential to avoid such situations for code clarity and reliability.
The ________ statement is used to skip the rest of the loop's body and continue with the next iteration.
- break
- continue
- exit
- return
In C and many other programming languages, the 'continue' statement is used to skip the current iteration and move to the next iteration within a loop. It allows you to bypass the remaining code in the loop body.
What is the impact of using inline functions on the size of the compiled binary?
- It depends on the compiler
- Larger compiled binary
- No impact on the binary size
- Smaller compiled binary
Inline functions tend to reduce binary size because they replace function calls with code directly inserted at the call site. This can lead to more efficient code and smaller binary sizes.
What happens to a local variable when the function in which it is defined finishes executing?
- It becomes a global variable
- It remains in memory
- It's accessible from other functions
- It's automatically freed
When a function finishes executing, the local variables defined inside it are automatically freed, and their memory is reclaimed. They do not persist after the function call.
What is the significance of using a pointer to a structure?
- It allows accessing the structure's elements directly
- It allows dynamic memory allocation and manipulation of structures
- It saves memory compared to not using a pointer
- It simplifies code but doesn't affect performance
Using a pointer to a structure allows direct access to its elements, enabling efficient manipulation and modification of the structure's data.