Syntax

C++ Lambda Expression Syntax

In C++, lambda expression: writes an inline anonymous function — auto add = [](int a, int b) { return a + b; };

Quick Answer

Syntax
auto add = [](int a, int b) { return a + b; };
C++Syntax

Lambda Expression

Code example
auto add = [](int a, int b) { return a + b; };

Writes an inline anonymous function.

Learn More

How to lambda expression in C++

  1. Open your C++ file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C++ Lambda Expression Syntax

Use auto add = [](int a, int b) { return a + b; };.

Related Syntax References

Frequently asked questions

What is the C++ syntax for lambda expression?

Use this pattern: auto add = [](int a, int b) { return a + b; };

Can I copy this C++ code example?

Yes. Use Copy code and adapt the example to your program.

Is this C++ syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify