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.

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.

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.

Robert notices that in a certain switch-case structure in his program, two different cases seem to execute sequentially without a break. What could be the reason behind this behavior?

  • Compiler error
  • Improper case order
  • Incorrect switch statement
  • Missing break statements
The reason behind two different cases executing sequentially without a break is most likely missing break statements within the cases. In a switch-case structure, if a break statement is omitted, execution will "fall through" to the next case. Robert should ensure that each case has the appropriate break statement to exit the switch statement after execution.

How does the compiler handle the default value of a function argument if it's not provided in a function call?

  • It assigns a random value
  • It assigns a value of 0
  • It assigns the default value specified in the function declaration
  • It raises a compilation error
It assigns the default value specified in the function declaration. When a function argument with a default value is not provided in a function call, the compiler assigns the value specified in the function's declaration. This behavior ensures that functions can be called with missing arguments.

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.

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.

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.

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.

Which loop can potentially become an infinite loop if no increment/decrement operation is performed on the loop control variable?

  • do-while loop
  • for loop
  • foreach loop
  • while loop
A while loop can potentially become an infinite loop if no increment or decrement operation is performed on the loop control variable within the loop body. This happens when the loop condition always evaluates to true.

Consider a for loop in C++ with an empty condition (i.e., for( ; ; )). What will be the behavior of this loop?

  • It will not compile
  • It will run indefinitely
  • It will run once and exit
  • It will throw an exception
A for loop with an empty condition (for( ; ; )) in C/C++ will run indefinitely until it is explicitly exited using a break statement or until an exit condition is encountered within the loop. It's often used for creating infinite loops, but caution is required to avoid infinite execution.

How does function overloading relate to the concept of polymorphism in C++?

  • Overloading simplifies polymorphism
  • Polymorphism replaces overloading
  • Polymorphism simplifies overloading
  • They are unrelated concepts
Polymorphism is a key concept in C++ that allows objects of different classes to be treated as objects of a common base class. Function overloading is a technique that enables polymorphism by providing multiple ways to call functions with different arguments, contributing to the versatility and flexibility of polymorphic behavior in C++.