← Back to archive

Stdle #59 · classes · 2026-08-04

What does this C++ snippet output?

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

#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {2, 4, 6};
for (auto& x : v) x += 1;
int sum = 0;
for (auto x : v) sum += x;
std::cout << sum << "\n";
return 0;
}
Classes
4 attempts left

Answer & explanation