When using the logical AND operator, if the left operand is false, the right operand is _______ evaluated. 

  • always 
  • sometimes 
  • never 
  • conditionally
In C++, the logical AND (&&) operator employs short-circuit evaluation. If the left operand is false, the right operand isn't evaluated because the overall result will already be false.

In C++, if a class makes a non-member function its friend, that function gets the ability to access the _______ and _______ members of the class. 

  • public, private 
  • private, protected 
  • public, static 
  • static, protected
In C++, when a non-member function is declared as a friend of a class, it can access both private and protected members of that class. Public members are accessible to all functions, so the unique ability granted by the friendship is access to the private and protected members.

Which function is used to read a single character from a file in C++? 

  • extract() 
  • get() 
  • fetch() 
  • pull()
The get() method is used to read a single character from a file in C++. While extract() is not a standard method for this purpose, fetch() and pull() are not associated with file reading in the standard C++ library.

Which operator is used to compare if two values are equal in C++? 

  • == 
  • = 
  • === 
  • !=
In C++, the == operator is used for equality comparison. It checks if the values of two operands are equal. On the other hand, = is an assignment operator, === is not valid in C++, and != is the not-equal operator.

What is the primary purpose of the ofstream class in file handling? 

  • Reading files 
  • Writing to files 
  • Deleting files 
  • Copying files
The ofstream class stands for output file stream. It is primarily used for performing output operations on files, meaning it's used for writing data to files. This class provides methods and properties needed to write data.

Which of the following data types is suitable for storing a character in C++? 

  • boolean
  • char 
  • float 
  • int 
In C++, the char data type is specifically designed to store characters. It typically occupies 1 byte in memory and can represent a single character from the ASCII table.

To prevent a class from being inherited, we declare it as _______. 

  • final 
  • static 
  • private 
  • mutable
In C++, the "final" keyword is used to prevent a class from being inherited. This means that no other class can be derived from a class declared as "final".

When class members are labeled as private, they are inaccessible outside the class, enforcing _______. 

  • encapsulation 
  • abstraction 
  • polymorphism 
  • inheritance
Encapsulation is a key concept in object-oriented programming where the internal details of a class are hidden and only specific functionalities are exposed. Making class members private enforces this encapsulation.

Regarding memory alignment and data packing, which of the following is true for structs in C++? 

  • Struct members are always packed tightly with no padding. 
  • Structs cannot be aligned in memory. 
  • Struct members have a defined order, but might have padding. 
  • Structs use dynamic memory for data storage.
Memory alignment and data packing are important considerations in C++ for optimizing memory usage and performance. In a struct, the order of declaration of members matters because the compiler might introduce padding between members to align data appropriately for the target architecture. This can affect the overall size of the struct.

How does the return statement interact with constructors or destructors in C++? 

  • It can exit a constructor prematurely. 
  • It causes the destructor to be called immediately. 
  • It can be used to return a value from the constructor. 
  • It has no use in constructors and destructors.
Constructors don't return values, so the return statement isn't used to return a value. However, it can be used to exit a constructor prematurely under certain conditions. Destructors also don't return values, and the use of a return statement in them would be to exit early, which is very rare.