Can two overloaded functions differ only by their return type in C++?

  • It depends on the C++ compiler being used.
  • No, C++ does not allow overloading based on return types.
  • Only in C++14 and later versions.
  • Yes, C++ allows overloading based on return types.
Yes, C++ allows overloaded functions to differ in return type. However, this alone isn't sufficient to distinguish between them; overloads must also differ in their parameter lists. This feature is known as "ad-hoc" polymorphism or function overloading.

Which of the following changes will NOT result in a different overloaded function in C++?

  • Changing the data type of parameters
  • Changing the number of parameters
  • Changing the order of parameters
  • Changing the return type of a function
In C++, changing only the return type of a function does not result in a different overloaded function. Overloaded functions are distinguished based on the number or type of parameters, not the return type.

Which data type is most suitable for storing a character in C++?

  • Char
  • Float
  • Int
  • String
The 'char' data type is most suitable for storing a single character in C++. It can hold characters like 'A', 'B', '1', '$', etc.

What do you call the process of calling a function in your program?

  • Function Declaration
  • Function Definition
  • Function Invocation
  • Function Prototype
The process of calling a function in your program is known as "Function Invocation" or simply "Calling a Function." This is where you use the function name followed by parentheses to execute the code within the function.

Tom is creating a game where the player's health decreases over time until it reaches zero. To implement this, which loop structure is best suited?

  • Do-While Loop
  • For Loop
  • Foreach Loop
  • While Loop
For Tom's game, a "While Loop" is the best choice. This loop continuously executes a block of code as long as a specified condition is true, making it suitable for decrementing the player's health until it reaches zero.

If no cases match in a switch statement and there's no default clause, then none of the switch blocks will execute.

  • catch
  • final
  • else
  • default
In a switch statement, if no cases match and there's no default clause, none of the switch blocks will execute. The default clause provides a fallback option to handle cases where none of the defined cases match the switch expression.

Which of the following best describes the difference between function declaration and definition?

  • A declaration tells the compiler about the function's name, return type, and parameters, while a definition provides the actual implementation of the function.
  • Declarations and definitions are the same thing.
  • Declarations define the function's behavior, whereas definitions merely declare its existence.
  • Declarations specify where a function can be used, while definitions specify how it should be used.
The primary difference between function declaration and definition lies in their purpose. A declaration informs the compiler about the function's signature, return type, and parameters, allowing the compiler to recognize it when used. On the other hand, a definition provides the actual implementation of the function, specifying what the function does.

Lily is receiving an error that says a particular header file is missing. What part of her program structure might she have forgotten to include?

  • #include Directives
  • Function Prototypes
  • Header Guards
  • using namespace std;
Lily might have forgotten to include the necessary #include directives in her program. These directives are used to include header files, and missing them can result in compilation errors due to undefined references.

Alice is developing a program that should run uniformly across multiple platforms. She is concerned about the size of data types. Which feature of C++ should she explore?

  • Data Type Modifiers
  • Preprocessor Directives
  • Standard Library Features
  • Standard Template Library (STL)
Alice should explore the Data Type Modifiers in C++. Data Type Modifiers like int32_t and int64_t are part of the header and ensure consistent data size across platforms, addressing her concern about data type size and platform uniformity.

Sarah wants to create a menu-driven program where the menu is displayed repeatedly until the user selects the "Exit" option. What control structure can assist her in achieving this?

  • Do-While Loop
  • For Loop
  • If-Else Statements
  • Switch Statement
To create a menu-driven program like Sarah's, the "Do-While Loop" is the most appropriate. It ensures that the menu is displayed at least once and then repeatedly as long as the user doesn't choose the "Exit" option, providing the desired functionality.