Quiz Entry - updated: 2026.07.14
What does the capture list [] do in a C++ lambda?
It specifies which variables from the surrounding scope the lambda can use — and whether it grabs each by value (a copy) or by reference.
| Capture | Meaning |
|---|---|
[] |
Capture nothing |
[x] |
Capture x by value (copy) |
[&x] |
Capture x by reference |
[=] |
Capture all used variables by value |
[&] |
Capture all used variables by reference |
[=, &x] |
All by value, except x by reference |
int multiplier = 3;
auto times3 = [multiplier](int x) { return x * multiplier; }; // by value
int count = 0;
auto counter = [&count]() { count++; }; // by reference
Tip: By-reference captures can read and modify the original variable; by-value captures hold a frozen copy (and can't be modified inside the lambda unless it's declared mutable).