What is the impact on performance when using float versus double in mathematical calculations in C++? 

  • float is faster 
  • double is faster 
  • No difference 
  • It depends on context
While "float" may use less memory, "double" provides higher precision. The performance impact depends on the architecture and context. Some architectures are optimized for double precision, making operations as fast, if not faster, than float operations.

How does a member function differ from a regular function in C++? 

  • It can only be called by an object. 
  • It does not have a return type. 
  • It always has parameters. 
  • It cannot be defined inside a class.
A member function in C++ is associated with an object of the class and has access to the object's data members. Unlike regular functions, member functions can be called using the object of the class and can manipulate the class's attributes directly. Regular functions don't have this implicit access.

To get the quotient of a division in C++, we use the _______ operator. 

  • &&
In C++, the forward slash (/) operator is used for division. When used between two integers, it gives the quotient of the division.

Which of the following is true about the complexity of the std::list::remove function? 

  • O(1) 
  • O(log n) 
  • O(n) 
  • O(n log n)
The std::list::remove function has a linear time complexity O(n). This is because it traverses the list once, removing all elements that match a specified value. As it potentially examines all elements, the complexity is linear.

The process of transferring the program control from where the exception was thrown to the catch block is known as _______. 

  • Throwing 
  • Handling 
  • Propagation 
  • Initialization
Propagation refers to the process where after an exception is thrown, it travels up the call stack until it's caught by an appropriate catch block or, if uncaught, the program terminates.

Which smart pointer in C++ retains shared ownership of an object through a pointer? 

  • auto_ptr 
  • unique_ptr 
  • weak_ptr 
  • shared_ptr
shared_ptr is a type of smart pointer in C++ that retains shared ownership of an object. This means multiple shared_ptr objects can own the same object, and the object will only be destroyed when the last shared_ptr owning it is destroyed or reset. This helps in preventing memory leaks and ensuring safer memory management.

What is the size (in bytes) of an int data type in most C++ implementations? 

  • 8
In most C++ implementations, particularly those that follow the x86 architecture and many 32-bit systems, an int data type occupies 4 bytes in memory. However, it's essential to note that the size can vary based on the platform and compiler.

What is the initial statement in a for loop typically used for? 

  • Incrementing 
  • Condition check 
  • Initialization 
  • Loop termination
In a for loop, the initial statement is typically used for initialization purposes. This is where variables, often loop counters, are initialized before the loop begins its execution.

What is the main purpose of using friend functions in C++? 

  • To increase the execution speed of programs 
  • To enhance object-oriented principles 
  • To achieve data encapsulation and abstraction 
  • To provide access to class's private and protected members from outside the class
While C++ uses classes and objects to encapsulate data and behavior, there are cases where you might want an external function (not belonging to the class) to access the private or protected members of the class. This is where friend functions come into play. They provide an exception to the usual encapsulation rules.

The diamond problem occurs due to _______ and can be resolved using _______. 

  • inheritance, interfaces 
  • encapsulation, templates 
  • multiple inheritance, virtual inheritance 
  • overloading, namespaces
The diamond problem is a complication that arises from multiple inheritance when two classes B and C inherit from A, and class D inherits from both B and C. If there is a method in A that B and C have overridden, and D does not override it, then which version of the method does D inherit: that of B, or that of C? This ambiguity can be resolved in C++ using virtual inheritance, ensuring that only one instance of the base class exists in the derived class.