Lambda capture as const cpp
#include <iostream>
int main() {
int x = 42;
// Step 1: Lambda function with const capture
auto lambda = [x]() {
// Step 2: Display the captured value
std::cout << "Captured value: " << x << std::endl;
// Step 3: Attempt to modify the captured value (will result in a compilation error)
// x = 10; // Uncommenting this line will result in a compilation error
};
// Step 4: Invoke the lambda function
lambda();
return 0;
}