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.

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 of the following C++ versions introduced the auto keyword for automatic type deduction? 

  • C++03 
  • C++11 
  • C++14
  • C++98 
The auto keyword for automatic type deduction was introduced in C++11. It allows the compiler to automatically deduce the type of a variable based on its initializer, enhancing code readability and maintainability.

In a system that processes user commands, you notice that the if-else chain for command processing has become excessively long and difficult to manage. Which refactorization strategy might be most effective? 

  • Introduce a command pattern 
  • Split the chain into functions 
  • Use a nested if-else 
  • Increase the use of comments
The Command Pattern encapsulates a command request as an object, allowing the parameters to be passed, queued, and executed at a later time. This makes the code modular, maintainable, and ensures decoupling between classes that invoke operations from those that perform operations.

A member function that is used to initialize the class members is known as a _______. 

  • initializor 
  • starter 
  • setter 
  • constructor
In C++, a constructor is a special member function that is automatically called when an object is instantiated. Its primary purpose is to initialize the object's attributes.

In the context of encapsulation, how does C++ handle data hiding differently from other programming languages? 

  • By using namespaces exclusively. 
  • By disallowing external access to data completely. 
  • Through the use of private and protected access specifiers only. 
  • By mandatory encapsulation for all classes.
C++ supports data hiding primarily through the use of private and protected access specifiers. Private members are strictly inaccessible from outside the class, while protected members are accessible in derived classes. This mechanism is more flexible compared to some languages that might use other strategies.