Which of the following containers in the Standard Template Library (STL) allows duplicate elements and keeps them in sorted order? 

  • std::vector 
  • std::set 
  • std::unordered_set 
  • std::multiset
The std::multiset container in the STL allows duplicate elements and keeps them in a sorted order based on their values. Unlike std::set, which ensures each element is unique, std::multiset allows storage of multiple instances of equivalent elements.

Indirect recursion involves a function calling another function that eventually calls the original function, forming a _______. 

  • cycle 
  • chain 
  • tree 
  • grid
Indirect recursion forms a cycle where function A calls function B (or a series of functions), and eventually, one of those functions calls back to function A. This loop of function calls forms the cycle characteristic of indirect recursion.

In C++, when a parameter is passed by value, what exactly is being passed to the function? 

  • Original value 
  • Memory address 
  • Reference 
  • Copy of the original value
When parameters are passed by value in C++, a copy of the original value is provided to the function. This means the function operates on this copy, and the original data remains unchanged outside the function scope.

In C++, to ensure that a derived class does not override a method of a base class, the method in the base class should be declared as _______. 

  • final 
  • constant 
  • private 
  • static
In C++, when a base class wants to prevent its method from being overridden in the derived classes, it declares that method as final. This ensures that the method retains its original functionality without any modifications.

In a multi-level inheritance scenario where multiple C++ classes are sharing methods and data, how might encapsulation and abstraction principles be applied to ensure data integrity and reduce complexity? 

  • Allow every class to modify the data of its base classes directly. 
  • Avoid using encapsulation and abstraction altogether. 
  • Use friend functions extensively for data access. 
  • Properly encapsulate data at each level and provide abstract interfaces for interactions.
In multi-level inheritance, it's essential to maintain data integrity and manage complexity. This is achieved by encapsulating data at every inheritance level, ensuring that each class exposes only what's necessary to its derived classes. Abstract interfaces further help in defining clear boundaries and interactions between classes.

What is the primary purpose of operator overloading in C++? 

  • To perform string operations 
  • To make code less readable 
  • To provide intuitive interfaces for custom data types 
  • To increase the execution speed of programs
Operator overloading in C++ allows operators to be redefined and used in a custom manner with user-defined types (like classes). This enhances code readability and allows for more intuitive programming when working with custom data types, making operations feel more natural.

An exception thrown by a function in the _______ block can be caught in the subsequent catch block. 

  • try 
  • throw 
  • return 
  • main
In the 'try' block, we place the code that might throw an exception. Any exception that occurs inside the 'try' block can be caught by the subsequent 'catch' block, allowing for appropriate error handling.

The return statement can be omitted in a function with a return type other than void if _______. 

  • it's a template function 
  • it throws an exception 
  • it's a friend function 
  • it's an inline function
In C++, if a function with a return type other than void does not have a return statement, but throws an exception that exits the function, it's acceptable and will not result in a compilation error.

In C++, _______ is used to restrict access to class members and maintain encapsulation. 

  • public 
  • protected 
  • private 
  • global
The "private" access specifier in C++ restricts access to class members, ensuring they can't be accessed or modified outside the class, thereby maintaining encapsulation and data integrity within the class.

What is the key difference between overriding and overloading a function in C++? 

  • Return type 
  • Number of arguments 
  • Function signature 
  • Polymorphism type
Overloading refers to defining multiple functions with the same name but different signatures (usually different number or type of parameters). Overriding, on the other hand, is related to inheritance and polymorphism where a derived class provides a specific implementation for a method that is already provided by its base class. In overriding, the method in the derived class should have the same name, return type, and parameters as the method in the base class. The key difference is thus related to polymorphism and inheritance for overriding versus method signature differences for overloading.