← Back to archive

Stdle #155 · modern · 2026-11-08

What does this C++ snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

#include <iostream>
int main() {
int calls = 0;
auto logged = [&calls](int x) { calls++; return x * x; };
int a = logged(2);
int b = logged(3);
std::cout << a << " " << b << " " << calls << "\n";
}
Modern
4 attempts left

Answer & explanation