A friend function is defined outside the class but has the ability to access the _______ members of the class. 

  • static 
  • private 
  • public 
  • mutable
A friend function, although not a member of a class, can access its private and protected members. This provides an external function the capability to interact closely with the internals of the class.

The loop do { /* code */ } while(_______); will always execute the code block at least once. 

  • FALSE 
  • TRUE 
  • sometimes
The "do-while" loop in C++ always executes its body once before checking the condition. So even if the condition in the "while" part is "false", the body of the loop will execute once. This differentiates it from the "while" loop which checks the condition before the first execution.

Which of the following scenarios is most suitable for using a switch-case statement? 

  • When comparing string values. 
  • When there are many conditions that can occur in any order. 
  • When the conditions are based on a range of values. 
  • When dealing with enumerated values.
The switch-case structure in C++ is best suited for scenarios where a single variable's value needs to be checked against a series of constants, often seen with enumerated values. It's a cleaner and more readable alternative to a long series of if-else statements in such cases.

You are optimizing a recursive algorithm for a real-time system where function call overhead is a critical concern. What strategy might be most effective in reducing the function call overhead while maintaining the logical structure of the algorithm? 

  • Use inline functions. 
  • Optimize the algorithm's base cases. 
  • Introduce parallel processing. 
  • Rely on external libraries.
Function call overhead is the extra time and resources needed when a function is called. Using inline functions can help reduce this overhead, especially in recursive algorithms, because the function's code gets inserted (or "inlined") at each point where the function is called, eliminating the need for the typical call and return process, which can be resource-intensive.

The operator used to determine the remainder when one number is divided by another is _______. 

  • +
In C++, the modulo operator % is used to determine the remainder of a division operation between two numbers. For example, 7 % 3 would yield a result of 1, as when 7 is divided by 3, the remainder is 1. It's a very useful operator, especially in situations that require calculations around loops and array indices.

Your team is developing a C++ application involving several classes with complex interrelationships and data handling. How can abstraction be effectively implemented to simplify the interactions between different class objects and the user? 

  • Use multiple inheritance for all classes. 
  • Avoid using classes and focus on procedural programming. 
  • Use a single class for all functions and data. 
  • Define clear interfaces for classes and hide complex implementations behind those interfaces.
Abstraction involves isolating the complex reality while exposing only the necessary parts. In the context of object-oriented programming, this means defining clear interfaces for classes, which allows interactions based on these interfaces, hiding the internal complex workings. This makes the software design more understandable and manageable.

When replacing nested if-else structures with a switch-case, what is a common pitfall to avoid? 

  • Ignoring the break statement 
  • Using non-integer values for cases 
  • Avoiding the default case 
  • Putting the default case at the beginning
When using switch-case statements, it's essential to remember to include the "break" statement at the end of each case. Without it, the program may execute subsequent cases, leading to unintended behavior known as "fall-through." The "break" statement ensures that once a match is found, no other cases are executed.

Which of the following data types is not a primitive data type in C++? 

  • int 
  • float 
  • string 
  • double
While "int", "float", and "double" are primitive data types in C++, the "string" data type is a part of the C++ Standard Library and is, in fact, a class, not a primitive data type.

How does encapsulation aid in reducing software development complexity? 

  • By allowing multiple inheritance. 
  • By segregating the program into separate modules. 
  • By promoting reusability of code. 
  • By bundling data and methods that operate on that data.
Encapsulation in C++ is the bundling together of data and the methods that operate on that data, restricting direct access to some of the object's components. This is a fundamental concept in object-oriented programming. By encapsulating data and functions into a single unit, we can hide the internal details and reduce complexity.

To prevent memory leaks, every call to new should be matched with a call to _______. 

  • delete 
  • free 
  • clear 
  • remove
When dynamic memory allocation is done using new, it's necessary to release that memory using delete to prevent memory leaks in C++. This ensures that every byte of memory allocated is properly released, maintaining the health and efficiency of the system.