The _______ function is automatically called when an object is destroyed.
- destructor
- finalizer
- deleter
- remover
In C++, when an object's lifetime ends, its destructor is called automatically. A destructor is a member function with the same name as its class preceded by a tilde (~).
In the context of recursion, what is a "recursive case"?
- A case that ends the recursion
- A scenario where recursion isn't used
- A case that repeats the same steps
- A case that calls the function itself recursively
In recursive algorithms, the "recursive case" refers to the scenario or condition where the function calls itself. This is contrasted with the "base case", which provides a termination criterion for the recursion. Without a base case, recursive functions can run indefinitely, leading to a stack overflow. The recursive case helps break down the problem into smaller, more manageable sub-problems.
Which access specifier in C++ allows a class member to be accessible only within the class and friends of the class?
- public
- private
- protected
- external
The private access specifier in C++ ensures that class members are only accessible within the class and not outside. Additionally, friend functions or classes can access these private members, but they remain hidden from other parts of the program.
What is the effect of the continue statement inside a for loop?
- It pauses the loop for a second
- It terminates the loop
- It jumps to the next iteration
- It reruns the current iteration
Inside a for loop, the continue statement causes the loop to skip the rest of its body and jump immediately to the next iteration. This is particularly useful when certain conditions within the loop need to be avoided for specific iterations.
How does an inline function improve the efficiency of a C++ program?
- By reducing memory usage
- By reducing runtime overhead
- By decreasing code size
- By performing lazy evaluation
Inline functions are a suggestion to the compiler to insert the complete body of the function wherever that function is used in the code. This can improve efficiency by eliminating the overhead of a function call, potentially leading to faster runtime performance.
The use of _______ in nested if-else structures can sometimes enhance readability and maintainability of the code.
- curly braces
- semicolons
- return statements
- comments
Using curly braces { } in nested if-else structures ensures clear block demarcation, helping readers understand the scope and flow of the code. Without them, it's easy to misinterpret where conditions start and end, especially in deep nesting.
The _______ header file in C++ provides a set of functions to manipulate C strings and arrays.
The header file provides a set of functions for manipulating C-style strings and arrays. This includes functions like strcpy, strlen, and others.
What is the purpose of the modulus operator (%) in C++?
- Multiplication
- Addition
- Division
- Remainder Calculation
The modulus operator (%) in C++ is used to calculate the remainder of a division operation between two integers. It is especially useful when we need to determine if a number is divisible by another.
In C++20, using enum with _______ allows specifying the underlying type and scope.
- type specificity
- class
- explicit type
- annotations
In C++20, when using enum with "class", it allows the developer to specify both the underlying type and the scope. This gives better control and clarity over enumeration definitions.
How does the performance of a switch-case statement compare to if-else if-else chains, especially when dealing with a large number of conditions?
- switch-case is always slower than if-else chains.
- switch-case and if-else chains have similar performance.
- if-else chains are always slower than switch-case.
- Performance is dependent on the compiler optimization.
While the performance of switch-case statements and if-else chains can depend on various factors, often, the switch-case statement is more optimized by compilers when dealing with a large number of conditions. The reason being, the compiler can optimize switch-case into a jump table or an array of branch instructions. However, it's always crucial to profile code in practice as the optimization might vary with compiler implementations and versions.