What are lambda expressions, and how does 'capturing' work (by value vs. by reference)?

Last updated 21 June 2026

  • A lambda is an inline anonymous function object ([capture](params) { body }). Its capture clause decides which surrounding variables it can use.

  • By value ([=], [x]) copies the variable at capture time and is safe to outlive it. Copies are const unless the lambda is mutable.

  • By reference ([&], [&x]) sees live changes but dangles if the lambda outlives the variable. Prefer by-value for lambdas that escape their scope.

  • https://cmp99.medium.com/lambda-function-mastery-in-c-e1b063437a5c
  • https://www.interviewbit.com/aws-lambda-interview-questions/
All C++ interview questions