← Back to archive

Stdle #37 · containers · 2026-07-13

What does this C++ snippet output?

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

#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
int evens = std::count_if(v.begin(), v.end(), [](int x){ return x % 2 == 0; });
std::cout << evens << "\n";
}
Containers
4 attempts left

Answer & explanation