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.

Which of the following scenarios is the most suitable for applying recursion? 

  • Iterating through elements in an array. 
  • Calculating the total sales of a company. 
  • Solving problems that have repetitive structures. 
  • Creating graphical user interfaces.
Recursion is particularly suitable for problems that exhibit repetitive or nested structures. Examples include problems like calculating factorial, traversing trees, or solving the Towers of Hanoi. Such problems can be broken down into smaller instances of the same problem, making them perfect candidates for a recursive approach.

When a float is converted to an int, the value is _______. 

  • truncated 
  • rounded 
  • incremented 
  • exponentiated
When a floating-point number is converted to an integer in C++, any fractional part is discarded (i.e., truncated). This does not involve rounding, just a simple removal of the decimal and beyond.

In professional C++ coding, it is often recommended to avoid using break and continue in favor of _______. 

  • structured logic 
  • recursive functions 
  • exception handling 
  • inline functions
While break and continue have their uses, over-reliance on them can make code harder to read and debug. Instead, it's often recommended to use clear and structured logic that doesn't rely on abrupt jumps within loops.

The friendship granted by a class A to a function or class B is _______ reciprocal, meaning [choose the correct statement]. 

  • always 
  • occasionally 
  • one-way 
  • not
The friendship in C++ is one-way. If class A declares class B or a function as its friend, it doesn't mean that class A automatically becomes a friend of class B or that function. Friendship must be explicitly granted. This means the granting of friendship is not reciprocal by default. Class B or the function would need to separately declare class A as a friend for the reverse to be true.

What is the impact of a function having a default argument? 

  • It allows function overloading. 
  • It allows multiple return types for the function. 
  • It can be called with fewer arguments than defined. 
  • It enhances runtime performance.
When a function has a default argument, it can be called with fewer arguments than it defines. The compiler will use the default value for any arguments not provided by the caller. This feature aids in providing flexibility while calling functions but doesn't directly enhance runtime performance.