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.

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 achieve runtime polymorphism in C++, _______ are used. 

  • classes 
  • macros 
  • virtual functions 
  • inline functions
Runtime polymorphism in C++ is achieved through the use of virtual functions. These are functions in the base class that you can override in derived classes. The decision about which method to call (the one in the base class or the one in the derived class) is made at runtime, based on the actual type of the object being pointed to, rather than the type of the pointer. This allows for more dynamic behavior and is a core feature of object-oriented programming in C++.

How would you implement a loop that executes a specific number of times and uses an iterator? 

  • Use a while loop and initialize the iterator outside the loop. 
  • Use a range-based for loop. 
  • Use a for loop and compare the iterator to the container's end iterator. 
  • Use recursive function calls.
To execute a loop for a specific number of times using an iterator, a common approach is to use a for loop. You initialize the iterator before the loop starts, use the loop's condition to check against the container's end iterator, and increment the iterator within the loop's iteration expression.

When dealing with binary files, the ios::binary mode should be used in conjunction with another mode such as _______. 

  • ios::in 
  • ios::out 
  • ios::app 
  • ios::trunc
When working with binary files in C++, the ios::binary mode is often paired with another mode to specify the operation, such as ios::out for writing or ios::in for reading. This ensures that the file is treated as a binary file.

What is the primary difference between direct and indirect recursion? 

  • Direct calls itself, while indirect calls another function that calls it back. 
  • Direct uses less memory than indirect. 
  • Direct is slower than indirect. 
  • Direct is always safer than indirect.
Direct recursion occurs when a function calls itself directly, whereas indirect recursion involves a function calling another function that eventually calls the original function. It's a cycle of calling between two or more functions.

In a for loop, what will happen if the condition is omitted? 

  • It will throw a syntax error. 
  • The loop will execute once. 
  • The loop will never execute. 
  • The loop will execute indefinitely.
In a for loop, if the condition is omitted, it's treated as always true. Therefore, the loop will execute indefinitely unless there's a break statement or some external factor that interrupts its execution.

The conditions in a switch-case statement must be of _______ data type. 

  • floating 
  • string 
  • integer or enum 
  • boolean
In a switch-case structure in C++, the conditions or cases must be of an integer or enumeration type. Floating-point and boolean values cannot be used as cases.

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.