What value does a function with return type void return? 

  • 0 
  • 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.

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.

Which of the following data structures is not implemented as a container in C++ STL? 

  • Array 
  • Linked List 
  • Hash Map 
  • Binary Tree
While the C++ Standard Template Library (STL) provides containers for dynamic arrays (vector), linked lists (list), and hash maps (unordered_map), there's no direct implementation for a binary tree. Trees are represented using set, map, multiset, and multimap, but they are based on balanced binary search trees (like Red-Black Trees) rather than generic binary trees.

Which type of function cannot be virtual in C++? 

  • Inline functions 
  • Constructor functions 
  • Friend functions 
  • Static member functions
Constructors in C++ cannot be virtual. When creating an instance of a derived class, it's essential to know the exact type of the object being created, so the correct constructor gets called. Making constructors virtual doesn't make sense in the context of object-oriented design, as it would introduce ambiguity in the object creation process.

To check for possible errors or failures in file operations, you should check the _______. 

  • failbit 
  • seekg 
  • open 
  • tellg
The failbit is a status flag in C++ streams that indicates a file operation failed. When working with file I/O in C++, it's crucial to check this flag (or use functions like fail()) to determine if a particular operation has encountered an error.