Alice has a class that includes a function to compute the area. She wants this function to compute the area for both circles (given radius) and rectangles (given length and breadth). Which concept can help her achieve this without renaming the functions?

  • Function overloading
  • Function overriding
  • Operator overloading
  • Polymorphism
Alice can achieve this using the concept of polymorphism, specifically method overloading. By overloading the computeArea function with different parameter types (radius for circles and length and breadth for rectangles), she can have a single function name that behaves differently based on the input, without renaming the functions.

What is the correct way to declare a function that takes two integers as parameters and returns their sum?

  • int sum(int a, int b) { return a + b; }
  • int sum(int a; int b) { return a + b; }
  • sum(int a, int b) { return a + b; }
  • void sum(int a, int b) { cout << a + b; }
Functions in C++ are declared by specifying their return type, followed by the function name and parameters enclosed in parentheses. The correct way to declare a function that takes two integers and returns their sum is by declaring the return type as int and specifying the parameters with commas in between. So, the correct declaration is int sum(int a, int b).

How does the __forceinline keyword (in some C++ compilers) differ from the inline keyword?

  • It disables inlining
  • It enforces inlining
  • It has no effect
  • It suggests inlining
The '__forceinline' keyword is a directive to the compiler that strongly enforces inlining of the function, even if the compiler would not typically inline it based on its heuristics. This keyword provides a more forceful hint to the compiler compared to the 'inline' keyword, ensuring that the function is inlined whenever possible.

Where are inline functions expanded?

  • At the calling point
  • In a separate source file
  • In a shared library
  • In the header file
Inline functions are expanded at the calling point. When you use the inline keyword, the compiler replaces the function call with the actual function code at the location where the function is called, reducing the overhead of a traditional function call.

Maria wrote a function that has a default argument. She noticed that sometimes it uses the default value, while other times it uses the value she provides. What could be the possible reason for this behavior?

  • Compilation Error
  • Compiler Optimization
  • Incorrect Function Call
  • Incorrect Function Definition
The possible reason for Maria's function sometimes using the default value and other times using the value she provides is an Incorrect Function Call. If she calls the function without providing an argument for the parameter with the default value, it will use the default value. However, if she explicitly provides an argument, the provided value will be used.

When a function is called recursively for a purpose other than for a placeholder purpose, it's termed as ______ recursion.

  • Direct
  • Head
  • Indirect
  • Tail
When a function calls itself as its last operation before returning, it's called 'tail recursion.' Tail recursion is often optimized by compilers, making it an efficient way to implement certain algorithms, like calculating factorials or traversing data structures.

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

  • Array
  • Boolean
  • Float
  • Integer
In C++, an array is not a primitive data type; it's a user-defined data type used to store a collection of elements of the same data type. Primitive data types include integers, floats, and booleans, among others.

Samuel is writing a C++ program and wants to ensure the program only compiles certain sections of the code when in debug mode. Which preprocessor directive can help him achieve this?

  • #ifdef DEBUG
  • #ifndef NDEBUG
  • #include
  • #pragma once
To conditionally compile code in C++, you can use preprocessor directives like #ifdef DEBUG, where DEBUG is typically defined in debug configurations. This allows Samuel to include or exclude specific sections of code based on whether he's in debug mode or not.

The ______ statement allows us to jump to a specific point in the code, though it's generally discouraged due to readability concerns.

  • Break
  • Continue
  • Goto
  • Return
The "goto" statement is used to transfer control to a specific labeled section of code. However, it's generally discouraged in modern programming because it can lead to unreadable and hard-to-maintain code. Structured programming practices promote the use of more structured control flow constructs like loops and conditional statements.

If not handled carefully, function overloading can introduce ______ in the code, making it difficult to identify the right function version to call.

  • Code Ambiguity
  • Code Clarity
  • Code Compilation
  • Code Optimization
If not handled carefully, function overloading can introduce Code Ambiguity in the code, making it difficult to identify the right function version to call. This ambiguity arises when multiple overloaded functions have similar parameter lists, causing confusion for the compiler and programmers. Careful design and naming conventions can mitigate this issue.