What does the new operator do in C++? 

  • Deletes memory 
  • Compares memory 
  • Allocates memory 
  • Modifies memory
The new operator in C++ is used to allocate memory on the heap at runtime. When you use new, it returns a pointer to the beginning of the block of memory it allocated. This is essential for dynamic memory management, as it allows more flexible storage allocation during program execution.

When dynamically allocating an array of integers using new, which of the following syntax is correct? 

  • int* arr = new int; 
  • int arr = new int[10]; 
  • int arr[10] = new int; 
  • int* arr = new int[10];
The correct way to dynamically allocate an array of integers in C++ using the new operator is int* arr = new int[10];. This syntax allocates memory for 10 integers on the heap and returns a pointer to the first element.

You are developing a multi-threaded application where multiple clients are sending data to a server. Each client is handled in a separate thread and communicates with the server in a loop. If a client sends an incorrect data format, the server should ignore it and wait for the next data. How might continue be used in this case? 

  • To terminate the client's thread. 
  • To send an error message back to the client. 
  • To disconnect the client. 
  • To skip the processing of the incorrect data and wait for the next input.
In a multi-threaded context, when a client sends data in an incorrect format, the server can utilize the continue statement to skip any further processing of that particular piece of data and return to the beginning of the loop to wait for the next data. This ensures that the server doesn't waste resources processing invalid data but remains ready to handle valid inputs.

How does friendship relation in C++ affect inheritance hierarchies, if at all? 

  • It overrides private inheritance. 
  • It allows base classes to access derived class members. 
  • It doesn't directly affect inheritance hierarchies. 
  • It breaks the "is-a" relationship in OOP.
Friendship is orthogonal to inheritance in C++. Declaring a function or class as a friend of another class doesn't have a direct impact on the inheritance hierarchy of classes. A friend function/class of a base class isn't automatically a friend of its derived classes.

What does the -> operator do in the context of pointers in C++? 

  • Duplicates the pointer 
  • Adds values 
  • Dereferences pointer and accesses member 
  • Multiplies pointer values
The -> operator in C++ is used with pointers to objects. It dereferences the pointer and accesses the member of the object. For instance, if p is a pointer to an object, p->member accesses the member of the object.

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.

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.