Inline functions should primarily be used for functions that are ______.

  • Complex
  • Frequently called
  • Rarely used
  • Short
Inline functions should primarily be used for functions that are frequently called. The decision to mark a function as inline should be based on how often it's called, as inlining is most beneficial when used with functions that are called frequently to reduce the function call overhead.

In nested loops, how does the break keyword behave when used inside the inner loop?

  • It generates a compilation error
  • It skips the current iteration of the inner loop
  • It terminates both the inner and outer loops
  • It terminates only the inner loop
When the break keyword is used inside an inner loop, it terminates only that inner loop and allows the outer loop to continue running. It does not affect the outer loop directly.

What will be the output of a while loop if its condition is initially false?

  • The loop will execute indefinitely
  • The loop will execute normally
  • The loop will execute once
  • The loop won't execute
If the condition of a while loop is initially false, the loop won't execute at all. It will skip the loop body and move on to the next code outside the loop.

Jessica is facing issues in her program where virtual functions with default arguments aren't behaving as expected. What should she be careful about while using default arguments with virtual functions?

  • Default Argument Scope
  • Function Overriding
  • Inline Functions
  • Virtual Function Resolution
Jessica should be careful about function overriding when using default arguments with virtual functions. Virtual functions are resolved at runtime based on the actual object's type, and default arguments are resolved at compile-time. This can lead to unexpected behavior if the derived class changes the default argument values.

What will be the result of the expression 5 & 3 in C++?

  • 0
  • 1
  • 15
  • 8
In C++, the '&' operator is a bitwise AND operator. When you perform a bitwise AND operation between 5 and 3 (binary 101 & 011), you get 001, which is decimal 1.

Which statement is best suited for selecting one of many blocks of code to be executed?

  • if-else statement
  • for loop
  • switch statement
  • while loop
The 'switch' statement in C++ is best suited for selecting one of many blocks of code to be executed. It allows you to define multiple code blocks (cases) and select one based on the value of an expression. This is particularly useful when you need to choose from several options.

What would be the potential issues when converting a double to an int in C++?

  • Loss of Precision
  • Overflow
  • Type Mismatch
  • Underflow
When converting a double to an int in C++, you may encounter potential issues such as the loss of precision. Double can represent fractional values, but int cannot, so any fractional part is truncated. This can lead to inaccuracies in your calculations.

David is getting a compilation error in his program where he has overloaded two functions. One accepts an integer and a float, and the other accepts a float and an integer. He calls the function with two float arguments. What might be the possible reason for the error?

  • Ambiguity
  • Incorrect Syntax
  • Missing Function Declaration
  • Type Mismatch
The compilation error might occur due to ambiguity. When David calls the function with two float arguments, the compiler cannot determine which overloaded function to call because both versions (integer-float and float-integer) are equally valid for the given arguments, resulting in ambiguity.

Fiona read about both inline functions and macros. In what situations might an inline function be a better choice over a macro?

  • When code size needs to be minimized, when conditional compilation is required, when multiple statement blocks are needed, when performance is the primary concern
  • When memory efficiency is crucial, when cross-platform compatibility is a priority, when macros introduce code duplication, when dynamic polymorphism is needed
  • When type safety is essential, when function parameters require validation, when complex operations are involved, when debugging is necessary
  • When variable scoping is critical, when the preprocessor directives are needed, when compile-time errors are acceptable, when portability is not a concern
Inline functions are often a better choice over macros in situations where type safety, parameter validation, complex operations, and debugging are essential. Unlike macros, inline functions provide type checking and encapsulation, making them more reliable and maintainable. Macros are generally used for conditional compilation and code size reduction but lack the type safety and debugging capabilities of inline functions.

Which of the following statements correctly starts a C++ program?

  • int begin() { }
  • int main() { }
  • int start() { }
  • void main() { }
The correct statement to start a C++ program is "int main() { }." In C++, the main function is defined with the return type "int," and it serves as the entry point for program execution. It can also accept command-line arguments within its parentheses.