Which of the following scenarios is the most suitable for applying recursion? 

  • Iterating through elements in an array. 
  • Calculating the total sales of a company. 
  • Solving problems that have repetitive structures. 
  • Creating graphical user interfaces.
Recursion is particularly suitable for problems that exhibit repetitive or nested structures. Examples include problems like calculating factorial, traversing trees, or solving the Towers of Hanoi. Such problems can be broken down into smaller instances of the same problem, making them perfect candidates for a recursive approach.

What is the impact of a function having a default argument? 

  • It allows function overloading. 
  • It allows multiple return types for the function. 
  • It can be called with fewer arguments than defined. 
  • It enhances runtime performance.
When a function has a default argument, it can be called with fewer arguments than it defines. The compiler will use the default value for any arguments not provided by the caller. This feature aids in providing flexibility while calling functions but doesn't directly enhance runtime performance.

Imagine you are developing an e-commerce system where different types of users (Admin, Buyer, and Seller) exist. Which inheritance model might be beneficial to maintain, expand, and utilize polymorphic behavior? 

  • Single Inheritance 
  • Multiple Inheritance 
  • Hierarchical Inheritance 
  • Hybrid Inheritance
Hierarchical inheritance is where a single class serves as a base class (superclass) for more than one derived class (subclass). In this scenario, the common attributes and methods of users can be part of the base class, while unique functionalities for Admin, Buyer, and Seller can be defined in their respective derived classes.

When is a copy constructor called in a C++ program? 

  • When an object is returned by value from a function. 
  • When we assign values from one object to another without the use of pointers. 
  • When an array of objects is created. 
  • When a function is called by value.
A copy constructor in C++ is called in several scenarios: 1) when an object is passed (by value) to a function, 2) when an object is returned (by value) from a function, 3) when an object is constructed based on another object of the same class, and 4) during the initialization of an object from another.

The enum class introduces _______ scope to prevent enumerators from polluting the namespace. 

  • global 
  • restricted 
  • local 
  • strong
The enum class introduces "strong" scoping. This ensures that the enumerator names are not directly accessible without the name of the enumeration, thus preventing name clashes and polluting the global namespace.

To find the first mismatching elements of two ranges in C++ STL, use the _______ algorithm. 

  • find 
  • mismatch 
  • search 
  • differentiate
The mismatch algorithm in C++ STL is used to compare two ranges and returns a pair of iterators pointing to the first position where the two ranges differ.

The _______ keyword is used to explicitly instantiate a template. 

  • extern 
  • instantiate 
  • explicit 
  • using
The "extern" keyword can be used to explicitly instantiate a template. While templates are usually instantiated implicitly when they are used, in certain scenarios, developers might want to instantiate a template explicitly to ensure that instantiation happens in a particular translation unit, and "extern" facilitates this.

When a class B is inherited publicly from a class A, then the protected members of class A will become _______ in class B. 

  • public 
  • private 
  • protected 
  • static
When inheritance in C++ is public, the protected members of the base class (Class A in this context) remain protected in the derived class (Class B). This ensures that they are accessible within Class B but not outside of it.

In a class template, the keyword _______ is used to create an instance of the template. 

  • class 
  • new 
  • template 
  • typename
In C++, when defining a class template, the "template" keyword is used. This keyword precedes the class definition and indicates to the compiler that it's a template definition. When creating an instance of the class template, you'll provide specific types for the template parameters, but the definition itself begins with "template".

A for loop that doesn’t specify the initialization, condition, and increment is known as a _______ loop. 

  • endless 
  • infinite 
  • forever 
  • boundless
In C++, when a for loop does not specify initialization, condition, and increment, it becomes an infinite loop. This means it will keep running indefinitely unless an external factor (like a break statement) interrupts its execution.