In a switch statement, what is the purpose of the default label?

  • It marks the end of the switch statement.
  • It specifies the condition for the switch statement.
  • It is executed when none of the case labels match the switch expression.
  • It is used to define another case statement.
In a switch statement, the default label is used to specify a block of code that is executed when none of the case labels match the switch expression. It serves as a fallback option when no specific case is satisfied, allowing you to handle unexpected or unspecified input gracefully.

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.

The ______ keyword is used to define a block of code that might be compiled conditionally

  • #define
  • #endif
  • #if
  • #ifdef
The correct keyword in this context is #if. It is used in preprocessor directives to conditionally compile blocks of code based on compiler settings or predefined macros.

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.

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.

If a function parameter has a default argument, must all subsequent parameters also have default arguments?

  • It depends
  • No, never
  • Yes, always
  • Yes, in some cases
No, never. In C++, if a function parameter has a default argument, subsequent parameters are not required to have default arguments. Default arguments allow calling a function with fewer arguments, and the missing arguments will take on their default values.

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.

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.

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.

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.

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.

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.