To loop over each character in a string named myString, one could use for(_______ : myString). 

  • auto& ch 
  • char& ch 
  • int i 
  • string str
Using auto& ch in a range-based for loop allows iterating over each character directly without copying. The auto keyword infers the type, making the code cleaner.

In a for loop, if a continue statement is executed, then the control jumps to _______. 

  • beginning of loop 
  • end of loop 
  • next iteration 
  • next statement
When a continue statement is encountered inside a loop, it skips the remaining portion of the current iteration and jumps to the start of the next iteration. In a for loop, this means the loop's update statement (like i++ in for(int i=0; i<10; i++)) gets executed.

The minimum possible value of a variable of type short int is _______. 

  • -32768 
  • -1024 
  • -2147483648
The short int type in C++ is typically 16 bits in size. Given that it's signed, half of the 2^16 possible values are negative. The range thus typically starts at -32768 and goes up to 32767.

What is the difference between break and continue in the context of a loop? 

  • break stops the loop, continue skips to the next iteration 
  • break skips to the next iteration, continue stops the loop 
  • Both have the same function 
  • Neither is used in loops
In a loop, the break statement is used to exit the loop prematurely, halting its execution entirely. On the other hand, the continue statement skips the remaining part of the current iteration and jumps to the next iteration.

What is the primary benefit of using class templates in C++? 

  • Faster execution 
  • Reduced memory usage 
  • Code optimization 
  • Genericity
Class templates in C++ provide the ability to create classes that can work with a variety of data types without the need to redefine the class for each type, offering a level of genericity and flexibility in code design.

You are tasked with designing a lightweight 3D point class to be used in a performance-critical graphics application. The class should store three float values and should allow public access to these without using getters and setters. Which user-defined data type would be best suited for this purpose? 

  • Class 
  • Struct 
  • Union 
  • Array
In C++, structs are typically used for lightweight user-defined data types. They default to public member access, making it easier to access the members directly without the need for getters and setters. Classes default to private access and are generally used when encapsulation is a primary concern.

What implications does the "Rule of Three" have in C++ class design? 

  • Always implement three constructors 
  • Always use three public members in a class 
  • Always create three instances of a class 
  • Manage the copy constructor, assignment operator, and destructor
The "Rule of Three" in C++ suggests that if a class requires a user-defined destructor, copy constructor, or assignment operator, it likely requires all three. This rule arises due to the intricacies of dynamic resource management (like memory allocation) in C++. Implementing or omitting one without the others can lead to unexpected behavior.

How does the virtual base class resolve the diamond problem in C++? 

  • By preventing multiple copies 
  • By duplicating base class 
  • By altering access specifiers 
  • By overloading functions
The diamond problem arises in C++ multiple inheritance when one class inherits from two classes that have a common base class. This can lead to ambiguity regarding which base class member should be accessed. The "virtual" keyword before the base class prevents the compiler from creating multiple instances of the base class, thus resolving the diamond problem.

In which type of inheritance do all derived classes share a common base class? 

  • Multiple Inheritance 
  • Hierarchical Inheritance 
  • Multilevel Inheritance 
  • Hybrid Inheritance
Hierarchical Inheritance is when multiple derived classes inherit from a single base class. All the derived classes share the features of that one common base class. This kind of inheritance structure resembles a hierarchy or tree structure.

To define an abstract class in C++, at least one member function must be declared as _______. 

  • inline 
  • pure virtual 
  • private 
  • constant
In C++, an abstract class is defined by having at least one pure virtual function. This means the function is declared but not defined within the class, ensuring that derived classes must implement it.