An infinite loop can be intentionally created for program structures like event listeners using for(;;), which is often referred to as a _______ loop. 

  • endless 
  • continuous 
  • forever 
  • looping
The term endless loop is often used to describe loops that have no termination condition, such as for(;;), and they continue executing indefinitely until externally terminated.

The _______ smart pointer in C++ does not allow the pointer to be shared among objects. 

  • unique_ptr 
  • weak_ptr 
  • shared_ptr 
  • custom_ptr
unique_ptr is a smart pointer that owns a dynamically allocated object exclusively. It ensures that only one unique_ptr can point to the object at a time. If another unique_ptr tries to take ownership, the original will relinquish its hold, ensuring uniqueness.

When implementing a finite state machine (FSM) in C++, which control structure might be more advantageous? 

  • Use if-else exclusively 
  • Use switch-case exclusively 
  • Use loops 
  • Depend on external libraries
A switch-case is generally more advantageous for implementing FSM in C++ because it improves readability when dealing with a set of known, discrete values (like states). It's also more performant than a chain of if-else statements in scenarios where there are multiple states.

In C++, using goto to jump over the initialization of a variable will result in _______. 

  • compilation error 
  • uninitialized variable 
  • runtime exception 
  • optimized behavior
Jumping over the initialization of a variable using the goto statement will result in a compilation error because the compiler will identify it as an attempt to bypass variable initialization.

Which type of inheritance in C++ restricts a derived class from inheriting from more than one base class? 

  • Single inheritance 
  • Multiple inheritance 
  • Hierarchical inheritance 
  • Hybrid inheritance
Single inheritance restricts a derived class to inherit from only one base class. While C++ supports multiple inheritance, where a class can inherit from more than one class, single inheritance ensures there's a straightforward lineage from the base to the derived class, avoiding complexities and potential ambiguities.

What will happen if a function does not return a value but has a return type other than void? 

  • It will cause a runtime error. 
  • It will return a random value. 
  • The program will not compile. 
  • The function will return zero.
When a function in C++ is declared with a return type other than void, it's a promise that the function will return a value of that type. If the function does not return any value, it will lead to a compilation error because the contract of returning a value (as per its declaration) is violated.

How does the C++ compiler handle different types of exceptions in a function template? 

  • It uses dynamic casting to determine the type. 
  • It uses overloading to handle exceptions. 
  • Each instantiation gets its own set of exceptions. 
  • The compiler ignores type-specific exceptions.
In C++, when a function template is instantiated, it gets its own version of the function, complete with its own set of exceptions. This means that if different instantiations of the function template throw different exceptions, each instantiation will have its own set of exceptions to catch. This provides a level of type-safety during exception handling.

The _______ function is used to move the file pointer to a specified position in the file. 

  • tellp 
  • seekp 
  • get 
  • put
The seekp function is used with output file streams to set the position of the next character to be inserted into the file. It essentially moves the file pointer to a specified position, allowing for efficient and targeted writing or modifying of file contents.

Which access specifier allows a class member to be accessible only within its own class and friends? 

  • public 
  • protected 
  • private 
  • global
The private access specifier in C++ ensures that class members are accessible only within the class they are defined and by friend functions or classes. This helps in the principle of encapsulation, keeping data and methods secure from unintended access.

When might using a table of function pointers be preferable over a switch-case statement for handling various cases/conditions? 

  • When handling a static set of conditions that seldom change. 
  • When trying to make the code more object-oriented. 
  • When handling a very large number of cases that might change dynamically or are loaded from an external source. 
  • When the conditions are based on string values.
Using a table of function pointers can be highly beneficial when there's a need to handle a dynamic set of conditions, especially if these conditions might be loaded from an external source or change during runtime. It allows for a more flexible and extensible approach than hard-coding numerous cases in a switch-case statement. Furthermore, it can lead to cleaner and more maintainable code in some scenarios.