Which loop is NOT compatible with the break statement in C++? 

  • for loop 
  • do-while loop 
  • while loop 
  • None, all loops support break
All loops in C++ (for, while, and do-while) support the break statement. The break statement is a control flow statement that can be used to exit a loop prematurely when a specific condition is met, irrespective of the loop's primary condition.

Which year was the C++ programming language introduced? 

  • 1970 
  • 1980 
  • 1983 
  • 1995
C++ was introduced in 1983 by Bjarne Stroustrup as an enhancement to the C language.

The syntax to declare a pure virtual function is to follow the function declaration with _______. 

  • '= 0' 
  • 'virtual' 
  • 'override' 
  • '= 1'
In C++, a pure virtual function is declared by assigning 0 in its declaration. The syntax is virtual function_name() = 0;. It indicates that the function doesn't have a body in this class and must be implemented in any non-abstract derived class.

What happens to the control flow of a program when the break statement is encountered inside a while loop? 

  • The program exits 
  • The while loop terminates and control moves to the next statement after the loop 
  • The loop skips to the next iteration 
  • The loop starts from the beginning
When a break statement is encountered inside a while loop, the loop terminates immediately and the control moves to the next statement following the loop, regardless of the loop's condition.

You are developing a game where numerous conditions dictate the character's state (e.g., running, jumping, idle, etc.). To manage these states efficiently, which approach might be preferable? 

  • Use multiple if-else statements 
  • Use a state pattern 
  • Use global variables 
  • Implement recursion
The State Pattern allows an object to change its behavior when its internal state changes. This would be ideal for game character states as it encapsulates state-specific behaviors and transitions, making the code more organized, scalable, and easy to extend with new states.

What is the impact of using a friend function on encapsulation in C++? 

  • It enhances it. 
  • It doesn't affect it at all. 
  • It undermines it. 
  • It strengthens the class hierarchy.
Friend functions can access the private and protected members of a class. This can lead to a breach in encapsulation as they can potentially expose or modify class internals outside the usual member function framework. This undermines the very purpose of encapsulation.

How does tail recursion differ from non-tail recursion in terms of performance? 

  • Tail recursion uses more memory. 
  • Non-tail recursion is always faster. 
  • Tail recursion can be optimized by compilers to iterative loops. 
  • They perform the same in all aspects.
Tail recursion is a form of recursion where the recursive call is the last operation in the function. Because of this, compilers can optimize tail recursive functions by transforming them into iterative loops, thus potentially improving performance and reducing stack usage.

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.