What happens if an exception is thrown but not caught in a C++ program? 

  • The program continues normally. 
  • The program crashes. 
  • The exception is ignored. 
  • The exception is retried.
When an exception is thrown but not caught in a C++ program, it leads to the termination of the program. This is because unhandled exceptions indicate unforeseen errors, and the program cannot predict how to safely continue in such cases.

An application performs arithmetic operations on various data types without modifying existing code. Which concept facilitates this? 

  • Template Functions 
  • Overloading 
  • Observer Pattern 
  • Factory Pattern
Template functions in C++ allow functions to operate on generic types. This means a single function template can work on different data types without any code modification. For arithmetic operations, using template functions ensures that the same function can work on integers, floats, complex numbers, etc.

In a graphics rendering engine, you need to store RGB color values. Which data type would be most appropriate for each color channel to balance memory usage and color depth? 

  • float 
  • int 
  • unsigned char 
  • long
Each RGB color channel requires values from 0 to 255. An unsigned char can store values in this range using just 8 bits, making it efficient in memory usage. Using larger data types like int or float would be wasteful in terms of memory without providing additional benefits for this use case.

A specific version of a function template created for a particular data type is referred to as a template _______. 

  • instantiation 
  • function 
  • specification 
  • meta-function
When a function template is used with a specific data type, the compiler creates a version of that function for the given type. This specific version is known as a template instantiation.

In a real-time gaming application written in C++, which smart pointer would you choose to manage instances of game objects, assuming the objects need to be shared across multiple game scenes? 

  • auto_ptr 
  • weak_ptr 
  • shared_ptr 
  • unique_ptr
shared_ptr allows multiple pointers to share ownership of the same object. This ensures that the object remains alive as long as there's at least one shared_ptr pointing to it, which is ideal for shared resources in games.

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.

Which of the following scenarios is most suitable for using a struct instead of a class? 

  • When needing multiple inheritance. 
  • When encapsulation and private members are vital. 
  • When only simple data storage without methods is required. 
  • When polymorphism is a primary concern.
In C++, both structs and classes can have member functions, inherit from others, and serve many of the same roles. The primary difference is the default access level (structs default to public; classes default to private). However, structs are conventionally used for simple data storage without associated behavior or methods.

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.