Off to a Good Start

Test your C++ programming skills by solving the given puzzle about function argument evaluation order and its implications.

Puzzle code

Carefully read the code given below:

Press + to interact
#include <iostream>
struct Logger {};
struct Configuration {};
Logger initializeLogger()
{
std::cout << "Initializing logger\n";
return Logger{};
}
Configuration readConfiguration()
{
std::cout << "Reading configuration\n";
return Configuration{};
}
void startProgram(Logger logger, Configuration configuration)
{
std::cout << "Starting program\n";
}
int main()
{
startProgram(initializeLogger(), readConfiguration());
}

Your task: Guess the output

Try to guess the output of the above code. Attempt the following quiz to assess your understanding.

Q

What is the expected output of the above code?

A)
Initializing logger
Reading configuration
Starting program
B)
Reading configuration
Initializing logger
Starting program
C)

Undefined behavior

D)

Compilation error

Let’s discuss this code and output together in the next lesson.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.