Search⌘ K
AI Features

Discussion: Off to a Good Start

Explore how C++ handles the order of function argument evaluation and its impact on program execution. Learn to identify when function calls depend on each other's order and how to write code that avoids unexpected behaviors caused by unspecified evaluation order.

Run the code

Now, it’s time to execute the code and observe the output.

C++ 17
#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());
}

Understanding the output

In this puzzle, we want to start a program that relies on a logger having been set up and a ...