Alex wants to create a menu-driven program that keeps displaying the menu until the user selects the 'Exit' option. Which loop is best suited for this task?

  • do-while loop
  • for loop
  • switch loop
  • while loop
Alex should use a do-while loop for this purpose. A do-while loop executes a block of code at least once and then repeats it based on a condition. It's ideal for menu-driven programs because it ensures that the menu is displayed at least once, even if the user chooses to exit immediately.

What is the size of the 'int' data type on a typical 32-bit system?

  • 16 bytes
  • 2 bytes
  • 4 bytes
  • 8 bytes
On a typical 32-bit system, the 'int' data type in C++ has a size of 4 bytes. This means it can store integer values within the range of approximately -2 billion to 2 billion.

Mia's C++ program has a function that's called before entering the main function. Which feature of C++ allows for such behavior?

  • Constructors
  • Destructors
  • Function Overloading
  • Inheritance
In C++, constructors are special member functions that are called automatically when an object of a class is created. If Mia's program has a function called before entering the main function, it's likely a constructor for an object instantiated before main.

How does a nested if-else structure differ from using else if?

  • Else if chains allow for mutually exclusive conditions
  • Else if chains are more readable and maintainable
  • Nested if-else structures are more efficient
  • Nested if-else structures can handle multiple conditions at once
A nested if-else structure consists of if statements inside other if statements. It can handle multiple conditions, but it may lead to less readable and maintainable code. In contrast, using else if chains allows for mutually exclusive conditions, making the code more structured and easier to follow. Else if chains are often preferred in scenarios where multiple conditions need to be checked.

Which of the following C++ data types is used to store a wide character?

  • char
  • int
  • short
  • wchar_t
The wchar_t data type in C++ is used to store wide characters. Wide characters are typically used to represent characters from extended character sets like Unicode. While char represents single-byte characters, wchar_t can hold multi-byte characters, making it suitable for wide character support.

Which of the following scenarios is NOT recommended for inline functions?

  • In Functions Called from Multiple Places
  • In Functions with Frequent Changes
  • In Functions with Heavy Computation
  • In Functions with Large Loops
Inline functions are not recommended in functions with large loops because it can lead to code bloat. The inline function code would be replicated within the loop, potentially increasing code size significantly.

Bob is noticing that his compiled program size is much larger than expected after he marked several lengthy functions as inline. What could be a reason for this?

  • Code Duplication
  • Compiler Optimization
  • Linker Error
  • Memory Leaks
One reason for Bob's compiled program size to increase after marking lengthy functions as inline is code duplication. When functions are marked as inline, their code is replicated at each call site. If the function is lengthy and called from multiple places, this can lead to increased code size. It's essential to strike a balance between inlining for performance and avoiding excessive code duplication.

Ethan is writing a large C++ project. To maintain clarity, he wants to keep function declarations separate from their definitions. How might he structure his program to achieve this?

  • Combine declarations and definitions in a single source file
  • Use header files (.h) for declarations and source files (.cpp) for definitions
  • Use inline functions for both declarations and definitions
  • Use namespaces to separate declarations from definitions
To keep function declarations separate from their definitions in C++, Ethan can use header files (.h) for declarations and source files (.cpp) for definitions. This practice enhances code organization, reusability, and maintainability in large projects.

In C++, if a floating-point number is assigned to an integer type, the value will be ______.

  • Rounded Up
  • Truncated
  • Type Error
  • Undefined
When a floating-point number is assigned to an integer type in C++, the value will be truncated. This means that the fractional part of the floating-point number is discarded, and only the whole number part is stored in the integer variable. It's essential to be aware of this behavior to prevent unexpected results in your code.

Which loop structure is best suited for scenarios where the number of iterations is known beforehand?

  • do-while loop
  • for loop
  • if-else loop
  • while loop
The for loop is best suited for scenarios where the number of iterations is known beforehand. It's a compact loop structure that allows you to initialize a variable, define a condition, and specify an increment or decrement in a single line. This makes it ideal for loops with a fixed number of iterations, such as iterating through arrays or performing a set number of calculations.