What is the minimum requirement for a recursive function to terminate successfully? 

  • It must have an iterative loop. 
  • It must have a base case. 
  • It should call other functions. 
  • It should be complex in nature.
For a recursive function to successfully terminate, it must have a base case. A base case is a condition under which the function stops calling itself and starts returning values. Without a base case, a recursive function would call itself indefinitely, leading to an infinite loop and, in most cases, a stack overflow error.

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.

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.

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.

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.

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.

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 relationship between abstraction and interfaces in C++? 

  • Interfaces are concrete implementations of abstraction. 
  • Abstraction is achieved using only interfaces. 
  • Interfaces ensure abstraction but not vice versa. 
  • C++ does not have interfaces.
In C++, there isn't a direct concept of "interfaces" as in some other languages. However, abstract classes with only pure virtual functions can act similarly to interfaces. These ensure abstraction by forcing derived classes to provide concrete implementations, but not all abstractions need to be interfaces.

The shared_ptr in C++ uses _______ counting to manage the memory of shared objects. 

  • reference 
  • object 
  • allocation 
  • array
shared_ptr uses reference counting, which means it keeps a count of the number of shared_ptr objects referring to the same memory location. When this count drops to zero (meaning no shared pointers are referring to the object), the memory is automatically deallocated.

Which of the following statements about the if-else control structure is true? 

  • It can only test for numeric conditions. 
  • It executes the else block if the if condition is true. 
  • It allows for multiple conditions to be checked in sequence. 
  • It requires both if and else parts.
The if-else control structure in C++ provides a way to perform decision-making operations. If the condition inside the 'if' block evaluates to true, the 'if' block of code is executed; otherwise, the 'else' block is executed, if present. It can be used to check multiple conditions in sequence by nesting or using "else if".

Which keyword is used in C++ to make a function virtual? 

  • static 
  • const 
  • virtual 
  • override
The keyword virtual is used in C++ to make a function virtual. When a function is declared as virtual, it can be overridden in any derived class. This allows for dynamic polymorphism, where the decision on which method version to execute is made at runtime based on the object's actual type.

In C++, function overloading is resolved at _______. 

  • runtime 
  • declaration time 
  • compile-time 
  • execution-time
Function overloading allows multiple functions in the same scope to have the same name as long as they have different parameter lists. In C++, the appropriate overloaded function is chosen at compile-time based on the function call's arguments.