How does C++ handle char literals that are assigned to unsigned char variables? 

  • Converts to signed char 
  • Preserves exact value 
  • Converts to int 
  • Triggers an error
When a char literal is assigned to an unsigned char variable, C++ preserves its exact value. If the char literal's value is negative, when assigned to an unsigned char, it wraps around using standard two's complement arithmetic.

Which of the following smart pointers does not take ownership of the pointed object? 

  • unique_ptr 
  • shared_ptr 
  • weak_ptr 
  • auto_ptr
weak_ptr is a smart pointer that holds a non-owning reference to an object managed by shared_ptr. It doesn't affect the reference count and won't prevent the object from being deleted.

Imagine you're working on a large-scale software project involving numerous classes. Some classes are instantiating objects of another, and suddenly an object is accidentally deleted. What techniques or principles might be used to safeguard against accidental deletion in such a situation? 

  • Use of smart pointers. 
  • Overloading the delete operator. 
  • Enabling strict type-checking. 
  • Always use dynamic allocation.
Smart pointers in C++ are template classes that manage the lifetime of dynamically allocated objects. They ensure that the objects they manage are properly deleted, thus preventing accidental deletions or memory leaks. Overloading the delete operator or enabling strict type-checking wouldn't inherently prevent accidental deletions.

What is the output of a function with a void return type? 

  • An integer 
  • A floating point number 
  • Nothing 
  • A character
In C++, a function declared with a void return type does not return any value. It is used when the function needs to perform an action but doesn't need to send any data back to the calling function.

When a class contains a pointer to memory allocated in class, we should define a _______. 

  • destructor 
  • constructor 
  • overloader 
  • allocator
When a class contains a pointer that has memory allocated to it dynamically, it's crucial to have a destructor to release that memory when the object is destroyed to prevent memory leaks.

When a continue statement is encountered in a loop, the program control resumes from _______. 

  • next statement 
  • loop condition 
  • beginning of loop 
  • end of loop
The continue statement, when encountered inside a loop, causes the program to skip the rest of the current iteration and move directly to the loop condition to check if the next iteration should commence. In essence, it "continues" to the next iteration of the loop without finishing the current one.

You're developing an embedded system with constrained memory. What should be the main consideration when choosing between using float and double data types? 

  • Precision needs 
  • Popularity of type 
  • Storage size requirement 
  • Arithmetic operations
In embedded systems with memory constraints, storage size becomes a primary concern. A float generally occupies 4 bytes, while a double occupies 8 bytes. Hence, if precision offered by float is acceptable for the application, it would be preferable to use float to save memory space.

Which keyword is used to inherit a class in C++? 

  • import 
  • extend 
  • inherit 
  • public
In C++, inheritance is specified by placing the colon (:) followed by an access specifier (public, protected, or private) and then the name of the base class. The public keyword itself is not used for inheritance, but rather indicates the type of inheritance.

In situations where the argument should not be modified, passing by _______ is preferable to ensure the original data remains unaltered. 

  • value 
  • reference 
  • name 
  • pointer
Passing by value means the function receives a copy of the argument. As a result, any changes made to the parameter within the function don't affect the original data, ensuring it remains unaltered outside the function's scope.

The _______ operator is used to compare whether two C++ values are not equal. 

  • != 
  • == 
  • >= 
  • <=
The != operator in C++ is the "not equal to" operator. It returns true if the operands on either side are not equal. For example, 5 != 3 evaluates to true, while 5 != 5 evaluates to false. The other options represent other comparison operations.