For a given function, once you start providing default values for arguments from the right, you cannot skip providing default values for subsequent arguments on the ______.

  • Left
  • Middle
  • None of the above
  • Right
For a function with default argument values, you can only provide default values for arguments starting from the right and not in the middle or left. Skipping arguments without default values in the middle would lead to a compilation error.

What is the main advantage of function overloading?

  • Better memory management
  • Faster execution of functions
  • Improved code readability and reusability
  • Smaller executable file size
The main advantage of function overloading is improved code readability and reusability. It allows you to use the same function name for logically related operations, making your code more intuitive and easier to understand. It also promotes code reusability by reducing the need to create distinct function names for similar tasks.

When declaring a function, which keyword is used to specify that the function should have a default argument?

  • #NAME?
  • const
  • default
  • default_argument
In C++, when declaring a function with default arguments, the = operator followed by a default value is used to specify the default argument. For example, int func(int a, int b = 0) declares a function func with a default argument of 0 for the parameter b.

When might an inline function increase the overall size of the compiled code?

  • When Used Sparingly
  • When Used in Critical Path Code
  • When Used in Header-Only Libraries
  • When Used in Isolated Modules
Inline functions can increase the overall size of the compiled code when used in header-only libraries. Since the function's code is included in each translation unit that includes the header, it can result in code duplication and larger executables.

The ternary operator, represented as ? :, can serve as a shorthand for a simple if-else statement.

  • ?else
  • ?if
  • ?then
  • ?when
The ternary operator, represented as ? :, provides a shorthand way to express a simple if-else statement. It evaluates a condition and returns one of two values depending on whether the condition is true or false. This concise syntax is often used to make code more compact and readable.

Given the expression a = b = c, which assignment is evaluated first?

  • Evaluation Order is Not Defined
  • a = b
  • b = c
  • c = a
In C and C++, assignment operators associate right-to-left. So, b = c is evaluated first, assigning the value of c to b, and then a = b assigns the value of b to a. This behavior is consistent with other binary operators in these languages.

Diane observed that even after explicitly marking a function as inline, the compiler did not inline it. What factors might the compiler consider when making this decision?

  • CPU clock speed, available RAM, function parameters, code comments
  • Compiler version, variable scope, CPU architecture, function visibility
  • Data types used in the function, available disk space, code organization, compiler brand
  • Function complexity, compiler optimization settings, available memory, function size
The decision of whether to inline a function is influenced by various factors. These include the complexity of the function, compiler optimization settings, available memory, and the size of the function. If the function is too complex or exceeds a certain size, the compiler may choose not to inline it, even if marked as such.

If a function is declared multiple times but defined only once, will the program compile successfully?

  • It depends on the compiler
  • It depends on the function name
  • No
  • Yes
Yes, if a function is declared multiple times but defined only once in a program, it will compile successfully. This is because function declarations inform the compiler about the function's signature and return type, allowing it to check for consistency when the function is called in different parts of the code. The definition provides the actual implementation.

Sarah is creating a math library and wants to write a sum function that can add two integers, two floats, or an integer and a float. Which C++ feature should she use?

  • Function Overloading
  • Function Overriding
  • Operator Overloading
  • Type Casting
Sarah should use Function Overloading. This allows her to define multiple functions with the same name but different parameter types. In this case, she can create overloaded functions that accept different combinations of integers and floats to achieve the desired behavior for her sum function.

In a switch statement, if there is no break statement after a case, what will happen?

  • The program will continue to execute the code in subsequent cases until a break statement is encountered
  • The program will generate a compilation error
  • The program will skip the current case and move to the default case
  • The program will throw a runtime exception
In C# and many other programming languages, when there is no break statement after a case, program execution will "fall through" to subsequent cases. This means that all code under subsequent case labels will be executed until a break statement is encountered or the switch statement ends. This behavior can be intentional when multiple cases should share the same code block.