What is the key difference between overriding and overloading a function in C++? 

  • Return type 
  • Number of arguments 
  • Function signature 
  • Polymorphism type
Overloading refers to defining multiple functions with the same name but different signatures (usually different number or type of parameters). Overriding, on the other hand, is related to inheritance and polymorphism where a derived class provides a specific implementation for a method that is already provided by its base class. In overriding, the method in the derived class should have the same name, return type, and parameters as the method in the base class. The key difference is thus related to polymorphism and inheritance for overriding versus method signature differences for overloading.

What is the minimum requirement for a recursive function to terminate successfully? 

  • It must have an iterative loop. 
  • It must have a base case. 
  • It should call other functions. 
  • It should be complex in nature.
For a recursive function to successfully terminate, it must have a base case. A base case is a condition under which the function stops calling itself and starts returning values. Without a base case, a recursive function would call itself indefinitely, leading to an infinite loop and, in most cases, a stack overflow error.

Which of the following algorithms is not present in the C++ STL? 

  • binary_search 
  • find 
  • sort 
  • magic_square
The C++ STL provides a plethora of algorithms for various operations, but "magic_square" is not among them. binary_search, find, and sort are standard algorithms provided in the STL.

You are debugging a C++ application and find that a goto statement is causing erratic jumps and consequently, unexpected behavior. Which refactoring approach might be the most beneficial to enhance code readability and maintainability? 

  • Replace goto with structured loops. 
  • Encapsulate the goto in a function. 
  • Add comments explaining the goto. 
  • Ignore it and move on.
Using goto statements can lead to spaghetti code that's hard to maintain and debug. It's considered a best practice to avoid using goto in C++. Replacing goto with structured loops or conditionals can often make the code clearer and more maintainable. While encapsulation is a good practice in general, it doesn't address the fundamental problems associated with goto. Comments can help but don't solve the root issue.

In a real-time graphics application where performance is critical, you need to manage a dynamically-allocated array that can change size. Which of the following STL containers would be the most appropriate choice considering the balance between dynamic size management and performance? 

  • vector 
  • list 
  • deque 
  • forward_list
The STL vector is a dynamic array that provides O(1) access time for its elements. It's efficient when resizing (amortized constant time for insertions/deletions at the end), making it suitable for scenarios requiring a balance between dynamic size management and performance.

What is the impact on performance when using float versus double in mathematical calculations in C++? 

  • float is faster 
  • double is faster 
  • No difference 
  • It depends on context
While "float" may use less memory, "double" provides higher precision. The performance impact depends on the architecture and context. Some architectures are optimized for double precision, making operations as fast, if not faster, than float operations.

How does a member function differ from a regular function in C++? 

  • It can only be called by an object. 
  • It does not have a return type. 
  • It always has parameters. 
  • It cannot be defined inside a class.
A member function in C++ is associated with an object of the class and has access to the object's data members. Unlike regular functions, member functions can be called using the object of the class and can manipulate the class's attributes directly. Regular functions don't have this implicit access.

In C++, function overloading is resolved at _______. 

  • runtime 
  • declaration time 
  • compile-time 
  • execution-time
Function overloading allows multiple functions in the same scope to have the same name as long as they have different parameter lists. In C++, the appropriate overloaded function is chosen at compile-time based on the function call's arguments.

Which keyword is used in C++ to make a function virtual? 

  • static 
  • const 
  • virtual 
  • override
The keyword virtual is used in C++ to make a function virtual. When a function is declared as virtual, it can be overridden in any derived class. This allows for dynamic polymorphism, where the decision on which method version to execute is made at runtime based on the object's actual type.

Which of the following statements about the if-else control structure is true? 

  • It can only test for numeric conditions. 
  • It executes the else block if the if condition is true. 
  • It allows for multiple conditions to be checked in sequence. 
  • It requires both if and else parts.
The if-else control structure in C++ provides a way to perform decision-making operations. If the condition inside the 'if' block evaluates to true, the 'if' block of code is executed; otherwise, the 'else' block is executed, if present. It can be used to check multiple conditions in sequence by nesting or using "else if".