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.

Which smart pointer in C++ retains shared ownership of an object through a pointer? 

  • auto_ptr 
  • unique_ptr 
  • weak_ptr 
  • shared_ptr
shared_ptr is a type of smart pointer in C++ that retains shared ownership of an object. This means multiple shared_ptr objects can own the same object, and the object will only be destroyed when the last shared_ptr owning it is destroyed or reset. This helps in preventing memory leaks and ensuring safer memory management.

What is the size (in bytes) of an int data type in most C++ implementations? 

  • 8
In most C++ implementations, particularly those that follow the x86 architecture and many 32-bit systems, an int data type occupies 4 bytes in memory. However, it's essential to note that the size can vary based on the platform and compiler.

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.

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.

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.

Which of the following is true about function overloading in C++? 

  • Functions must be in the same scope 
  • Return type can be used to differentiate overloaded functions 
  • Overloaded functions must have a different number of parameters 
  • Only member functions can be overloaded
Function overloading in C++ allows multiple functions with the same name but different parameters (types and/or number). They must be in the same scope. Return type alone cannot be used to distinguish overloaded functions, and both member and non-member functions can be overloaded.

Which of the following is true regarding stack unwinding in C++ exceptions? 

  • It is a process of releasing memory. 
  • It relates to multi-threading. 
  • It is the process of calling destructor functions. 
  • It is the process of rolling back a database transaction.
Stack unwinding in C++ refers to the process that takes place when an exception is thrown, and control is transferred from the point of the throw statement to the handler. During this, all the local objects in the intervening frames are properly destroyed.

How can the return statement be used in a function that returns void? 

  • To exit the function immediately. 
  • To return a value of type int. 
  • To pause the function execution. 
  • To skip to the next function.
In a void function, the return statement doesn't return a value but can be used to exit the function prematurely. For instance, in certain conditions, if there's no need to execute the rest of the function, a return statement can be used to exit out, improving efficiency and logic clarity.