How does a range-based for loop work in C++11 and above? 

  • It works only on arrays and not on containers. 
  • It iterates over elements using indices. 
  • It allows iterating over all elements in a container or array directly. 
  • It requires manual initialization of iterators.
In C++11 and newer versions, the range-based for loop provides a more readable syntax to iterate over all elements of a container or an array. The loop automatically gets the begin and end iterators of the range and iterates over each element without needing manual indexing.

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.

You are tasked with enhancing the performance of a critical path in an application. You identify a function that is called very frequently as a potential optimization target. Which specific aspect of the return statement could you focus on to possibly improve performance, especially considering modern C++ standards? 

  • Returning by value. 
  • Returning by pointer. 
  • Using return in a loop to optimize iterations. 
  • Returning by reference or moving.
In modern C++, when considering performance-critical paths, it's beneficial to understand the difference between returning by value and returning by reference or using move semantics. Especially with the advent of Rvalue references in C++11, returning by reference or moving can avoid unnecessary copies and lead to significant performance improvements. Returning by pointer is less idiomatic and might not convey ownership semantics clearly.

In the context of floating-point representation, what is the role of the mantissa? 

  • Determines the sign 
  • Determines the exponent 
  • Stores the actual digits 
  • Determines the base
In floating-point representation, the number is typically represented as: (-1)^sign * mantissa * (base^exponent). The mantissa is responsible for storing the actual digits of the floating-point number, while the exponent determines the position of the decimal point and the sign determines its sign.

The first commercially available C++ compiler was named _______. 

  • CFront
  • Clang 
  • GCC 
  • Turbo C++ 
CFront was the first commercially available C++ compiler. It was developed by Bjarne Stroustrup at Bell Labs as a front-end to the C compiler. This compiler played a crucial role in the early evolution and popularization of C++.

How does C++ treat an enum regarding its type and size? 

  • As a float type with fixed size 
  • As an integer type with variable size 
  • As a class with member functions 
  • As a boolean type
Enums in C++ are treated as integer types. Their actual size can vary based on the compiler and the number of values they hold, but typically, they have the size of an int. C++11 introduced scoped enumerations (enum class) that offer better type safety, but fundamentally, they're still integers.

If a break statement is encountered in a nested loop, it will exit _______. 

  • the outermost loop 
  • the innermost loop 
  • the function 
  • the program
When a break statement is encountered within a nested loop, it only exits the loop in which it's directly contained, i.e., the innermost loop. It does not affect any outer enclosing loops.

What is a friend function in C++? 

  • A function that always returns a friend object. 
  • A private function of a class. 
  • A function that can access private members of a class. 
  • A function that can only be called within its class.
A friend function in C++ is a special function that, although not a member of a class, has access to its private and protected members. This is used to allow non-member functions and other classes to access such members.