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.

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.

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.

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.

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.

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.

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.

A C++ project is exhibiting memory leaks, but it is unclear where they originate. Considering the tools and features available in modern C++, which approach might be most efficient in tracking down and resolving the memory leaks? 

  • Re-writing the entire project from scratch 
  • Use new and delete extensively 
  • Use std::shared_ptr and std::weak_ptr 
  • Utilize memory profiling tools like Valgrind
Memory profiling tools, like Valgrind, inspect a program's memory usage in real-time and can identify where memory is being allocated but not released. By pinpointing the exact location of leaks, developers can focus their efforts on specific parts of the code, rather than resorting to broad changes or extensive manual checks.

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.

Which file opening mode in C++ will allow you to append data at the end of the file’s content? 

  • ios::binary 
  • ios::in 
  • ios::app 
  • ios::trunc
The "ios::app" mode in C++ stands for "append". When a file is opened in this mode, data will be appended to the end of the file's content if it already exists. If the file does not exist, a new one is created.

When a pointer is passed to a function, the function receives _______? 

  • A copy of the actual data 
  • The memory address 
  • The function stored in memory 
  • A blueprint of the data
When a pointer is passed to a function, the function gets a copy of the pointer, which contains the memory address of the data. Therefore, the function can access and modify the original data through this memory address. This is different from passing the actual data, where the function would receive a copy of that data, and any changes wouldn't affect the original data.

Which class is primarily used for performing input operations on files in C++? 

  • ofstream 
  • ifstream 
  • fstream 
  • filestream
The ifstream class stands for input file stream and is primarily used for performing input operations on files. This means it is used for reading data from files, making it crucial for file handling in C++.