What will happen if a function does not return a value but has a return type other than void? 

  • It will cause a runtime error. 
  • It will return a random value. 
  • The program will not compile. 
  • The function will return zero.
When a function in C++ is declared with a return type other than void, it's a promise that the function will return a value of that type. If the function does not return any value, it will lead to a compilation error because the contract of returning a value (as per its declaration) is violated.

What does the -> operator do in the context of pointers in C++? 

  • Duplicates the pointer 
  • Adds values 
  • Dereferences pointer and accesses member 
  • Multiplies pointer values
The -> operator in C++ is used with pointers to objects. It dereferences the pointer and accesses the member of the object. For instance, if p is a pointer to an object, p->member accesses the member of the object.

How can you access the last element of a C++ STL vector named "myVector"? 

  • myVector.end() 
  • myVector.last() 
  • myVector.back() 
  • myVector[myVector.size()]
The member function back() provides direct access to the last element in a vector. On the other hand, myVector.end() returns an iterator pointing to the position after the last element, and myVector[myVector.size()] would result in undefined behavior since it tries to access out-of-bounds memory. There's no last() function in vector.

You’re maintaining a legacy C++ codebase which has limited comments and documentation. You encounter an erratic bug that only appears in the optimized build. What strategy might be most effective in isolating and fixing the bug? 

  • Add extensive documentation first
  • Compare optimized and unoptimized assembly 
  • Refactor the entire codebase 
  • Use printf debugging 
Comparing the optimized and unoptimized assembly can provide insights into how the compiler is altering the code, potentially revealing the source of the erratic behavior. It's a meticulous process but can be effective for bugs that only manifest in optimized builds due to compiler transformations.

What is a potential risk of using recursion? 

  • Always faster than loops. 
  • Cannot handle large input data. 
  • Guarantees better readability. 
  • Uses less memory than loops.
One of the potential risks of using recursion is that it can lead to excessive memory use, especially when dealing with large input data. Every recursive call adds a new layer to the system's call stack, which can eventually result in a stack overflow if unchecked.

When performing a bitwise AND operation with a number and 0, the result is always _______. 

  • positive 
  • zero 
  • negative 
  • unchanged
When any number is bitwise AND-ed with 0, the result is always 0. This is because the AND operation yields 1 only if both bits being compared are 1; otherwise, it yields 0.

What is the output of the logical NOT (!) operator when applied to a non-zero operand? 

  • Undefined 
  • None
In C++, any non-zero value is considered as true. The logical NOT (!) operator inverts the truthiness of its operand. So, if applied to a non-zero (true) operand, the output will be false, which is represented as 0.

Unlike if-else, switch-case in C++ does not support _______ type for case values. 

  • floating-point 
  • integer 
  • character 
  • boolean
In C++, switch-case constructs don't support floating-point types for case values. This means you can't use float or double values as cases. On the other hand, if-else structures can easily handle conditions based on floating-point values.

The maximum value that can be stored in an unsigned char is _______. 

  • 127 
  • 1024 
  • 256 
  • 255
The unsigned char data type in C++ uses 8 bits (1 byte) for storage. This means it can store values ranging from 0 to 2^8-1, which is 0 to 255.

A class whose objects cannot be created is known as a _______ class. 

  • abstract 
  • virtual 
  • static 
  • inline
An abstract class in C++ is a class that cannot be instantiated, meaning objects of the class cannot be created directly. Abstract classes are intended to be inherited by other classes.