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.

Which operator will give the remainder of a division operation? 

  • / 
  • * 
  • + 
  • %
The '%' operator in C++ is called the modulus operator. It is used to determine the remainder of a division operation between two integers. For example, '7 % 3' will return 1 as the remainder.

When an array is passed to a function, it is always passed by _______. 

  • value 
  • reference 
  • name 
  • address
When an array is passed to a function, it is passed by name, which essentially means the address of the array is passed. This allows functions to modify the original array. The behavior is similar to passing by reference.

A class that contains at least one pure virtual function is called a(n) _______. 

  • subclass 
  • instantiated class 
  • abstract class 
  • inherited class
An abstract class in C++ is a class that contains at least one pure virtual function. This means the class cannot be instantiated and is meant to be inherited by other classes that provide implementations for the pure virtual functions.

What potential issue might arise when using switch-case statements with enumerated types? 

  • Memory leaks. 
  • Switching to an incorrect case accidentally. 
  • Skipping the default case. 
  • Not handling newly added enumerators in the switch.
When using switch-case statements with enumerated types, if a new enumerator is added to the enumeration and not correspondingly handled in the switch statement, it can lead to potential issues or bugs. This is because the switch might not have a case for the new enumerator, and if there's no default case or if the default case doesn't handle it appropriately, the program can behave unpredictably.

If an exception is thrown and not caught anywhere in the program, function _______ is called. 

  • exit() 
  • main() 
  • terminate() 
  • throw()
If an exception is thrown but not caught anywhere in the program, the special function terminate() is called in C++. By default, terminate() ends the program. However, a programmer can change the function that gets called by using set_terminate().

In what scenario might the compiler ignore the inline keyword for a function? 

  • If the function has recursion. 
  • If the function is a template. 
  • If the function is defined outside the class. 
  • If the function uses a single return statement.
The inline keyword is a suggestion to the compiler, not a command. While compilers use their heuristics to decide, functions with recursion are typically not inlined because inlining recursive functions can lead to significant code bloat and possible stack overflow issues.