A ______ statement can be used as a control structure to repeatedly execute a block of code as long as a particular condition remains true.

  • For
  • If
  • Switch
  • While
In programming, a "while" statement is a control structure that creates a loop. It repeatedly executes a block of code as long as a specified condition remains true. This is useful for scenarios where you want to perform an action multiple times until a certain condition is met.

A common mistake that leads to infinite loops is forgetting to update the ______ variable.

  • Counter
  • Loop
  • Control
  • Iterator
A common mistake that leads to infinite loops is forgetting to update the 'Counter' variable. In loops, the counter variable is crucial for controlling the loop's progress and termination.

In nested loops, if a break statement is executed inside the inner loop, the control will exit the ______ loop.

  • Inner
  • Outer
  • Both inner and outer
  • None of the above
In nested loops, a break statement is used to exit the innermost loop. When it's executed, control exits the inner loop, not the outer one. Therefore, the correct option is 'Inner.'

Which C++ statement is used to make a single conditional decision?

  • for loop
  • if statement
  • switch statement
  • while loop
The 'if' statement in C++ is used to make a single conditional decision. It allows you to execute a block of code only if a specified condition is true. This is fundamental for controlling the flow of your program based on conditions.

If you have multiple conditions, which statement can be used to test multiple conditions sequentially?

  • do-while loop
  • for loop
  • if-else statement
  • switch statement
The 'if-else' statement in C++ is used when you have multiple conditions to test sequentially. It allows you to define different blocks of code to execute for different conditions, providing a structured way to handle multiple possibilities.

When you need to store an integer without any sign (only positive), you should use ______ data types.

  • long
  • short
  • signed
  • unsigned
In C++, the unsigned data type is used to store integers without any sign, which means they can only represent positive values or zero. This is useful when you need to work with quantities that should not have negative values, like the number of items in a collection.

How can you ensure that a certain block of code is executed regardless of whether the condition in the if statement is true or false?

  • By placing the code outside of any if statement
  • By using the break keyword
  • By using the finally block in a try-catch-finally structure
  • By using the return statement
To ensure that a certain block of code is executed regardless of whether the condition in the if statement is true or false, you can use the finally block in a try-catch-finally structure. The code in the finally block runs after the try block, whether an exception is thrown or not, making it useful for cleanup or resource release tasks.

For a loop to be infinite in C++, the condition in a while loop must always evaluate to ______.

  • 0
  • 1
  • FALSE
  • TRUE
To create an infinite loop in C++, the condition in a while loop must always evaluate to true. This means that as long as the condition is true, the loop will continue executing indefinitely. Infinite loops can be useful in some scenarios but should be used with caution to avoid program hang or crashes.

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).