To create an infinite loop using a while loop, we can use the statement while(_______). 

  • FALSE 
  • "infinite"
A while loop continues execution as long as the condition within the parentheses is true. By using "while(1)", where 1 stands for true in the context of the loop's condition, it creates an infinite loop.

What is the primary purpose of the return statement in C++ functions? 

  • To loop the function 
  • To display a value 
  • To exit the function 
  • To allocate memory
In C++, the return statement is primarily used to conclude the execution of a function and provide a value back to the caller. It signifies the end of a function's execution and optionally returns a value to the calling function.

What will be the output of a loop if the continue statement is placed before the print statement inside the loop? 

  • The loop will not output anything 
  • The loop will output values continuously 
  • The loop will only output the first value 
  • The loop will output alternate values
If the continue statement is placed before the print statement inside a loop, it will cause the loop to skip the print statement during every iteration. Therefore, nothing will be outputted by the loop.

A function that does not return a value has a return type of _______. 

  • void 
  • int 
  • char 
  • bool
In C++, if a function is not returning any value, its return type is void. It indicates that the function does not return a value to the calling function.

In C++, the return statement cannot be used inside a _______. 

  • constructor 
  • destructor 
  • class 
  • loop
In C++, constructors are used for initializing objects. They don't return values, not even void. Therefore, the return statement is not allowed inside a constructor.

Imagine a function that performs file I/O and may throw an exception. What might be a concern if this function is used inside a constructor, and how might it be addressed? 

  • The object may not be fully constructed. 
  • Memory leaks could occur. 
  • An invalid object can be accessed elsewhere in the code. 
  • File operations might be slow.
If an exception is thrown during the construction of an object, that object's destructor will not be called since the object was never fully constructed. This can lead to resource leaks or other inconsistencies. It's crucial to ensure that if a constructor might throw an exception, all resources acquired up to that point are properly released to prevent such issues. Proper exception handling and resource management techniques, like RAII, are essential.

Which loop structure is guaranteed to execute at least once even if the condition is false? 

  • for loop 
  • while loop 
  • do-while loop 
  • switch-case
The do-while loop is designed to execute its block of code at least once before checking the condition. This ensures that the loop body runs even if the condition is false from the start.

In which scenarios could the use of goto be considered acceptable or even advisable? 

  • To enhance the readability of deeply nested loops. 
  • To replace exception handling mechanisms. 
  • For breaking out of multiple nested loops. 
  • To implement recursive functions.
While the use of "goto" is generally discouraged in modern programming due to making code harder to read and maintain, there are rare cases, like breaking out of multiple nested loops or complex error handling before exceptions were widely adopted, where its use might be considered.

How might you address concerns about function templates impacting compilation times and binary size in a high-performance scientific computing application? 

  • Use inline functions 
  • Reduce template instantiation 
  • Avoid using templates 
  • Optimize template definitions
Function templates can increase both compilation times and the size of the binary due to multiple instantiations for different data types. One way to address these concerns is by reducing unnecessary template instantiations, making sure only required instantiations are compiled, and using techniques like explicit instantiation.

In C++, _______ functions cannot be virtual. 

  • inline 
  • recursive 
  • overloaded 
  • default
Inline functions in C++ are expanded at the place where they are called, rather than being invoked. Because of this, they cannot be virtual as the virtual mechanism relies on function calls.