The _______ statement is used to prematurely exit a switch-case block.
- return
- break
- continue
- exit
The "break" statement is used to exit a switch-case block prematurely. Once a "break" is encountered, the control jumps out of the switch-case structure.
Imagine you are implementing a high-frequency trading system...
- std::fstream with buffering
- mmap based I/O
- std::cout
- std::ofstream with std::ios::sync_with_stdio(false)
mmap based I/O, which maps a file into memory, allows for very fast file operations since it avoids certain system calls and can result in fewer memory-copy operations than traditional read/write functions. This is crucial for high-frequency systems where latency is critical.
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 expression a×b can be represented as a _______ b in C++.
- *
- %
- +
- -
In C++, the asterisk () is used as the multiplication operator. So, "a×b" is represented as "ab" in C++ programming.
Which method will you use to write a single character to the file stream in C++?
- put()
- write()
- insert()
- push()
The put() method is used to write a single character to a file stream in C++. The write() method is typically used to write blocks of binary data, while insert() and push() aren't standard methods for this purpose in C++ streams.
The _______ keyword is used when we want to explicitly pass by reference but prevent the function from modifying the argument.
- const
- static
- virtual
- inline
The const keyword is used in C++ to indicate that a value shouldn't be modified. When passing an argument by reference, using const before the parameter type ensures that the function does not alter the original data, providing a level of safety.
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.