In C++, a size of long double is at least _______ bytes. 

  • 10 
  • 12 
  • 16
In C++, the size of long double is compiler-dependent. However, according to the C++ standard, it is at least 8 bytes or the size of a double, whichever is greater. Some compilers may allocate more.

Using templates excessively can lead to an issue known as _______. 

  • recursion 
  • template bloat 
  • overloading 
  • specialization
Excessive use of templates can result in code that has much larger compiled sizes than equivalent non-template code. This phenomenon, where the binary gets bloated due to templates, is known as template bloat.

When an enum is declared, it creates a new _______. 

  • function 
  • data type 
  • variable 
  • class
When an enumeration (enum) is declared in C++, it essentially creates a new user-defined data type. This allows the programmer to define variables of this enumeration type and assign any of its enumerator values to these variables.

In C++, an enum can be used to create _______. 

  • classes 
  • named constants 
  • functions 
  • variables
In C++, an enumeration (enum) is a user-defined data type that consists of integral constants. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by one. They are essentially a way to create named integral constants.

While creating a networking application, you find a need to define a data type that can hold various data related to a network packet, such as its ID, source, destination, and payload. You also require a function to calculate the checksum of the packet. Which user-defined data type in C++ would be best suited for this use case? 

  • Class 
  • Struct 
  • Union 
  • Namespace
Classes in C++ are versatile data structures that can encapsulate both data members and member functions. In this scenario, since we need to define various data attributes for the packet and also include a function to calculate checksum, a class is the most appropriate choice.

A game has a scoring system where players earn points. The game needs a feature to evenly distribute bonus points among players and also determine any remaining points that can't be evenly distributed. Which arithmetic operator is essential to determine the number of leftover points? 

  • %
In this scenario, the modulus operator (%) is essential. When dividing the bonus points by the number of players, the modulus operator gives the remainder, which represents the number of leftover points that can't be evenly distributed among the players. This allows the game to allocate bonus points fairly and determine if there are any undistributed points.

What value does a function with return type void return? 

  • Null 
  • It doesn't return a value 
  • An undefined value
A function with a void return type doesn't return any value. It is often used for functions that perform an action but do not need to send a result back to the caller.

What is the primary purpose of encapsulation in object-oriented programming in C++? 

  • Code compression 
  • Memory saving 
  • Hide complexity 
  • Code sharing
Encapsulation is a core concept in object-oriented programming. Its primary purpose in C++ and other OOP languages is to hide the internal representation, or state, of an object from the outside and to bundle the data (attributes) and the methods (functions) that operate on the data into a single unit, thus hiding complexity.

In C++, the method used to allocate memory dynamically during runtime within the object is called _______. 

  • malloc 
  • new 
  • alloc 
  • reserve
In C++, dynamic memory allocation for objects is achieved using the new operator. Unlike malloc in C, new in C++ initializes the allocated memory.

The problem in which a derived class may inherit the same member more than once from a base class hierarchy is known as the _______ problem. 

  • Replication 
  • Duplication 
  • Diamond 
  • Looping
The "Diamond Problem" arises in object-oriented languages that support multiple inheritance. If a class is derived from two classes that have a common base class, the derived class may inherit the same member more than once.