Which of the following statements about the struct and class keywords is true? 

  • Only structs can have member functions 
  • Structs are always public, and classes are always private 
  • Both can have member functions, but default access is different 
  • Classes support inheritance, structs don't
Both struct and class in C++ can have member functions, data members, and can support inheritance. The primary difference is the default access level: members of a struct are public by default, whereas members of a class are private. Other functionalities between them are essentially identical.

To remove all instances of a particular value from a C++ STL vector, you should use the _______ algorithm. 

  • find 
  • sort 
  • erase 
  • remove
While erase can remove elements from a vector, to efficiently remove all instances of a value, you'd first use remove to move those elements to the end and then use erase. This is known as the "erase-remove" idiom in C++.

The keyword _______ is used to access the base class’s members in the derived class. 

  • super 
  • this 
  • parent 
  • base
In C++, the "base" keyword is not actually used. The correct way to access base class members is through the use of the base class name or the scope resolution operator. However, "base" is a term from C#.

The concept of encapsulation involves bundling the data () and the methods () that operate on the data into a single unit. 

  • objects, functions 
  • variables, operators 
  • members, methods 
  • attributes, functions
Encapsulation is a key concept in object-oriented programming where the data (members) and the functions (methods) that operate on this data are bundled together as a single unit known as a class.

Which of the following is a correct statement about friend functions in C++? 

  • They are member functions of a class 
  • They can be inherited by derived classes 
  • They always improve performance of the program 
  • They do not have access to the 'this' pointer of the class
In C++, the 'this' pointer is an implicit pointer to the object on which a member function is called. Since friend functions are not member functions of a class, they do not have access to this pointer. They operate as external functions with special access permissions.

In a C++ application, you have a stream of data being logged... 

  • Write to a temporary file first 
  • Use std::ofstream::flush after every write 
  • Use file locking mechanisms 
  • Implement journaling or write-ahead logging
Implementing journaling or write-ahead logging means changes are first logged to a separate, sequential log. In case of failures, this log can be used to bring the file back to a consistent state. This provides a safeguard against data corruption or loss during unforeseen events.

The members of a struct are _______ by default. 

  • private 
  • public 
  • protected 
  • static
In C++, the members of a structure (struct) are public by default. This means they can be accessed from functions outside the structure. This is in contrast to the members of a class, which are private by default and cannot be accessed or viewed outside of the class.

Which parameter-passing method does not allow the function to modify the actual argument? 

  • By value 
  • By reference 
  • By pointer 
  • By name
When parameters are passed by value, a copy of the argument is made for the function. Any modifications to this copy do not affect the original argument outside the function.

How does C++ handle the virtual table in a multiple-inheritance scenario? 

  • Single table for all classes 
  • Separate tables for each base class 
  • A combination of both depending on visibility 
  • Virtual tables are not used
In C++, when a class inherits from multiple base classes, each base class will have its own virtual table. Thus, an object of the derived class will have separate virtual tables for each inherited class to handle dynamic dispatch for function calls, ensuring correct method resolution.

A pointer passed by value to a function allows the function to change the _______ to which the pointer points. 

  • value 
  • address 
  • direction 
  • data type
When a pointer is passed by value to a function, the function gets a copy of the pointer. This means that the function can modify the data at the address the pointer points to, but it cannot change the address of the original pointer itself.