No, C has no support for lambda expressions.

If you're willing to use C++, Boost has a library that emulates lambdas. Also, C++0x will have built-in support for lambda expressions.

There wasn't a huge demand for lambda expression support in C at the time, so the language didn't support it.

Answer from In silico on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › lambda-expression-in-c
Lambda Expression in C++ - GeeksforGeeks
A lambda expression can access variables from the enclosing scope, which regular functions cannot do directly. We can capture external variables from the enclosing scope in three ways using capture clause:
Published: April 26, 2026
🌐
Hackaday
hackaday.com › 2019 › 09 › 11 › lambdas-for-c-sort-of
Lambdas For C — Sort Of | Hackaday
November 2, 2023 - However, in C you have to define a function by name and pass a pointer — not a huge problem, but it can get messy if you have a lot of callback functions that you use only one time. It’s just hard to think up that many disposable function names. However, if you use gcc, there are some nonstandard C features you can use to get most of what you want out of lambda expressions...
Discussions

Why does C not have lambdas/anonymous function expressions?
There are two basic ways to implement closures: A custom calling convention: Callers are aware they're calling a closure and so pass the closure context to the callee, perhaps as a hidden argument. Closures are nearly always implemented this way, including in C++. For C, as a lingua franca platforms would need to define this calling convention / ABI so that different implementers could all each others closures just as they can call each others functions. Since this doesn't exist, closures in language implementations using this approach are incompatible with C interop (ex. can't turn a C++ closure into a function pointer). Build a trampoline by allocating a little bit of executable memory, essentially like using a small JIT compiler. Callers do not need to be aware they're calling a closure, and a plain C calling convention is sufficient. GNU C closures are implemented this way, as are CPython's ctypes callbacks. However, frequently allocating executable memory requires significant trade-offs in performance or security. It may not even be possible on some platforms. This is also an implicit allocation — which is not in the spirit of C — and someone has to manage its lifetime. (GNU C manages it by using an automatic allocation.) Unless you're willing to make the trade-offs in the second approach — which is available to you if you use GCC — neither fits C well. More on reddit.com
🌐 r/C_Programming
35
6
August 7, 2022
How can this C code have lambda - Stack Overflow
Blocks are a non-standard extension added by Apple Inc. to Clang's implementations of the C, C++, and Objective-C programming languages that uses a lambda expression-like syntax to create closures within these languages. More on stackoverflow.com
🌐 stackoverflow.com
simple lambda like functions in C
These nested functions aren’t standard C and they won’t work on Clang or MSVC. More on reddit.com
🌐 r/C_Programming
26
11
March 12, 2024
How does the lambda expression work
A lambda simplifies code for a two part situation: You have some generalized code that basically says "When we're ready to act, please tell me what C++ code to run" and You want to run the C++ function code once and only once. You don't want to type out lots of boilerplate function definition stuff. What made lambdas click for me is when I realized they're just predicates or struct functors in simpler form. Imagine that the compiler basically expands lambdas into the old fashioned struct functors. That's it. Lambdas will make this cplusplus.com example cleaner: https://cplusplus.com/reference/forward_list/forward_list/remove_if/ . I'm cleaning up the code a bit and reposting it below. The example is about using a linked list with items, and then removing items of a given criteria. Because you don't have access to the nodes, and iterators aren't really a clean way to do this, we end up needing to pass in logic. A function predicate and a functor, not exciting yet... #include #include // A function bool single_digit(const int& value) { return (value < 10); } // A functor struct oddFunctor { bool operator() (const int& value) { return (value % 2) == 1; } }; int main() { std::forward_list mylist = { 7, 80, 7, 15, 85, 52, 6 }; mylist.remove_if(single_digit); // mylist now only contains 80 15 85 52 mylist.remove_if(oddFunctor()); // mylist now only contains 80 52 return 0; } Now let's say we want to make it even more flexible. Instead of just checking if a number is odd, we want to remove all numbers divisible by something the user specifies. Redoing that with lambdas, and adding another example. This is exciting #include #include // A messier functor struct DivisibleByFunctor { public: DivisibleByFunctor(const int divisibleValue) { this->divisibleValue = divisibleValue; } bool operator() (const int& value) { return (value % divisibleValue) == 0; } private: unsigned int divisibleValue{}; }; int main() { std::forward_list mylist = { 7, 80, 7, 15, 85, 52, 6 }; std::forward_list secondlist = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13 }; std::forward_list thirdlist = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13 }; // Lambda! The function is gone! All logic here is in one line. myList will contain 80 15 85 52 mylist.remove_if([](const int& value) {return (value < 10); }); // Lambda! The struct is gone! All logic here is in one line. myList will contain 80 52 mylist.remove_if([](const int& value) {return (value % 2) == 1; }); int divisibleValue; std::cout << "Values divisible by this should be removed: "; std::cin >> divisibleValue; // Ugly functor way. Boo! Requires a messy struct up above secondlist.remove_if(DivisibleByFunctor(divisibleValue)); // Lambda with capture of a local variable! No struct needed! All logic in one line! thirdlist.remove_if([divisibleValue](const int& value) { return (value % divisibleValue) == 0; }); return 0; } More on reddit.com
🌐 r/cpp_questions
24
7
December 9, 2023
People also ask

When should I use lambda expressions in C++?
You can use lambda expressions in C++  when defining small, one-time-use functions, working with STL algorithms, handling event-driven programming, or multithreading operations.
🌐
intellipaat.com
intellipaat.com › home › blog › lambda expressions in c++
Lambda Expressions in C++ - Intellipaat
Can lambda expressions modify captured variables?
Lambda captures variables as const when passed by value; thus, to modify captured variables, a lambda, the mutable keyword has to be specified inside the body of the lambda.
🌐
intellipaat.com
intellipaat.com › home › blog › lambda expressions in c++
Lambda Expressions in C++ - Intellipaat
What are common mistakes when using lambda expressions?
The common mistakes are capturing variables incorrectly, modifying non-mutable captured variables, inefficiently capturing large objects by value, and returning references to local variables.
🌐
intellipaat.com
intellipaat.com › home › blog › lambda expressions in c++
Lambda Expressions in C++ - Intellipaat
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › cpp › lambda-expressions-in-cpp
Lambda expressions in C++ | Microsoft Learn
This article defines what lambdas are, and compares them to other programming techniques. It describes their advantages, and provides some basic examples. Lambda expressions vs. function objects ... #include <algorithm> #include <cmath> void abssort(float* x, unsigned n) { std::sort(x, x + n, // Lambda expression begins [](float a, float b) { return (std::abs(a) < std::abs(b)); } // end of lambda expression ); }
🌐
Reddit
reddit.com › r/c_programming › why does c not have lambdas/anonymous function expressions?
r/C_Programming on Reddit: Why does C not have lambdas/anonymous function expressions?
August 7, 2022 -

It would not seem to hard to implement to allow a programmer to use a construct similar to:

int (*add)(int, int) = (int(int x, int y)){return x+y;};

This would simplify code that requires callback functions such as qsort or bsearch or various UI libraries that use callbacks to define, for example, a buttons behavior when pressed. Is there any specific reason they elected not to support this, and require us to define named static functions instead?

Top answer
1 of 7
8
There are two basic ways to implement closures: A custom calling convention: Callers are aware they're calling a closure and so pass the closure context to the callee, perhaps as a hidden argument. Closures are nearly always implemented this way, including in C++. For C, as a lingua franca platforms would need to define this calling convention / ABI so that different implementers could all each others closures just as they can call each others functions. Since this doesn't exist, closures in language implementations using this approach are incompatible with C interop (ex. can't turn a C++ closure into a function pointer). Build a trampoline by allocating a little bit of executable memory, essentially like using a small JIT compiler. Callers do not need to be aware they're calling a closure, and a plain C calling convention is sufficient. GNU C closures are implemented this way, as are CPython's ctypes callbacks. However, frequently allocating executable memory requires significant trade-offs in performance or security. It may not even be possible on some platforms. This is also an implicit allocation — which is not in the spirit of C — and someone has to manage its lifetime. (GNU C manages it by using an automatic allocation.) Unless you're willing to make the trade-offs in the second approach — which is available to you if you use GCC — neither fits C well.
2 of 7
6
Why are people obsessed with making C like python or whatever language they learned first? It's like asking why my bicycle only has two wheels, when your red wagon has four.
Top answer
1 of 2
10

This behavior seems to be specfic to newer versions of Clang, and is a language extension called "blocks".

The Wikipedia article on C "blocks" also provides information which supports this claim:

Blocks are a non-standard extension added by Apple Inc. to Clang's implementations of the C, C++, and Objective-C programming languages that uses a lambda expression-like syntax to create closures within these languages. Blocks are supported for programs developed for Mac OS X 10.6+ and iOS 4.0+, although third-party runtimes allow use on Mac OS X 10.5 and iOS 2.2+ and non-Apple systems.

Emphasis above is mine. On Clang's language extension page, under the "Block type" section, it gives a brief overview of what the Block type is:

Like function types, the Block type is a pair consisting of a result value type and a list of parameter types very similar to a function type. Blocks are intended to be used much like functions with the key distinction being that in addition to executable code they also contain various variable bindings to automatic (stack) or managed (heap) memory.

GCC also has something similar to blocks called lexically scoped nested functions. However, there are some key differences also note in the Wikipedia articles on C blocks:

Blocks bear a superficial resemblance to GCC's extension of C to support lexically scoped nested functions. However, GCC's nested functions, unlike blocks, must not be called after the containing scope has exited, as that would result in undefined behavior.

GCC-style nested functions also require dynamic creation of executable thunks when taking the address of the nested function. [...].

Emphasis above is mine.

2 of 2
7

the C standard does not define lambdas at all but the implementations can add extensions.

Gcc also added an extension in order for the programming languages that support lambdas with static scope to be able to convert them easily toward C and compile closures directly.

Here is an example of extension of gcc that implements closures.

#include <stdio.h>

int(*mk_counter(int x))(void)
{
    int inside(void) {
        return ++x;
    }
    return inside;
}

int
main() {
    int (*counter)(void)=mk_counter(1);
    int x;
    x=counter();
    x=counter();
    x=counter();
    printf("%d\n", x);
    return 0;
}
Find elsewhere
🌐
Joshdata
joshdata.me › lambda-expressions.html
Lambda Expressions: A Guide
These languages still have types, usually the same types as in the C-family languages, but they’re only for the values computed in memory, not for variables in source code. A lambda expression is a function written in a shorthand syntax, and we’ll start by looking at the syntax of lambda ...
🌐
Cppreference
en.cppreference.com › w › cpp › language › lambda.html
Lambda expressions (since C++11) - cppreference.com
The lambda expression is a prvalue expression of unique unnamed non-union non-aggregate class type, known as closure type, which is declared (for the purposes of ADL) in the smallest block scope, class scope, or namespace scope that contains the lambda expression.
🌐
Oboe
oboe.com › learn › mastering-modern-c-idioms-kynj8p › lambda-expressions-2
Something went wrong! Show Error
Oboe's learning courses have moved to a chat-first experience. Start a new chat and we'll help you explore any topic
🌐
Reddit
reddit.com › r/c_programming › simple lambda like functions in c
r/C_Programming on Reddit: simple lambda like functions in C
March 12, 2024 -

I was diving in reddit and I found the following post

I thought: maybe it is possible to do something similar in C with macros or something along those lines.

After some research, I found the following topic on GCC manual:
Statements and Declarations in Expressions

Well, with this construction, it's possible to instruct the compiler to define a function and call it in place, like we can do with lambdas. Look the example bellow:

#include <stdio.h>
int call_callback(void (*callback)()){
    callback();
}

void foo() {
    printf("foo\n");
}

int main(void) {
    call_callback(foo);
    call_callback(({
        void _() {
            printf("this is a lambda?\n");
        }
        (void (*)())_;
    }));
}

For me, it's very interesting. We encounter many situations and libraries that deal with callback functions, and personally, I often find myself declaring simple functions that are only called once. I believe that in these cases, this construct would work very well.

However, debugging it might be challenging.

🌐
Embarcadero
blogs.embarcadero.com › the-advanced-guide-to-lambda-expression-in-c-software
The Advanced Guide To Lambda Expression In C++ Software – Embarcadero RAD Studio, Delphi, & C++Builder Blogs
September 25, 2022 - The syntax for a lambda expression consists of specific punctuation with = [ ] ( ) { ... } series. ... Datatype is its type like int, float, class, etc.
🌐
Medium
medium.com › @weidagang › modern-c-lambda-expressions-63fc0c2b8186
Modern C++: Lambda Expressions. This blog post is part of the series… | by Dagang Wei | Medium
June 22, 2024 - Changes to the original variable won’t be reflected inside the lambda, and vice-versa. Mutable Lambdas: By default, lambdas capture by value variables as const. To modify them, you'll need to use the mutable keyword. Each lambda expression you create has its own unique, unnamed type.
🌐
Cprogramming.com
cprogramming.com › c++11 › c++11-lambda-closures.html
C++11 - Lambda Closures, the Definitive Guide - Cprogramming.com
How to begin Get the book · C tutorial C++ tutorial Game programming Graphics programming Algorithms More tutorials
🌐
Built In
builtin.com › software-engineering-perspectives › c-plus-plus-lambda
C++ Lambda Expressions Explained | Built In
Summary: C++ lambdas, introduced in C++11, are expressions that allow for defining anonymous function objects (functors). They enhance readability, support callbacks and reduce boilerplate code compared to traditional function objects.
🌐
Medium
medium.com › embedworld › lambda-functions-in-c-compact-and-expressive-code-04e556c7da11
Lambda Functions in C++: Compact and Expressive Code | by Wadix Technologies | Embedded Systems Technologies | Medium
November 17, 2025 - The following example demonstrates how a lambda captures a value defined in the outer scope. The variable factor is declared before the lambda expression and added to the capture list using the equal symbol, making the value available during the computation.
🌐
Quora
quora.com › How-do-we-write-and-use-lambda-functions-in-pure-C-indirectly-instead-of-C
How do we write and use lambda functions in pure C indirectly instead of C++? - Quora
Answer (1 of 5): https://en.wikipedia.org/wiki/Anonymous_function#C_(non-standard_extension) > C (non-standard extension)[edit] The anonymous function is not supported by standard C programming language, but supported by some C dialects, such as GCC[52] and Clang. GCC[edit] GNU Compiler Colle...
🌐
Reddit
reddit.com › r/cpp_questions › how does the lambda expression work
r/cpp_questions on Reddit: How does the lambda expression work
December 9, 2023 -

I just want an example using a normal function and it laymans terms. All the examples I find are too complicated so help would be appreciated.

Top answer
1 of 8
22
Lambdas are usually thought of as an alternative to a function, but it's more accurate to think of it as an alternative to an object. Objects can be called like functions using the "()" operator, just like they could be added together by defining a "+" operator. Objects which define operator() are called "functors". A functor is more powerful than a simple function, because it has data. For example, the object could have an int field which gets incremented each time the "()" operator is invoked, and that int could be used within the operator, to get different behavior each time it is called. A lambda is just a short and simple way of defining a functor. The functor's fields are your local variables wherever the lambda was declared (taken by reference or by copy), and the "()" operator is defined as the code block of your lambda. In other words, lambdas are merely an anonymous struct generated by the compiler so that you don't have to write one by hand. I'm on mobile, so I don't want to throw up a code example, sorry. But look at examples of functors to see what lambdas help you avoid writing.
2 of 8
5
A lambda simplifies code for a two part situation: You have some generalized code that basically says "When we're ready to act, please tell me what C++ code to run" and You want to run the C++ function code once and only once. You don't want to type out lots of boilerplate function definition stuff. What made lambdas click for me is when I realized they're just predicates or struct functors in simpler form. Imagine that the compiler basically expands lambdas into the old fashioned struct functors. That's it. Lambdas will make this cplusplus.com example cleaner: https://cplusplus.com/reference/forward_list/forward_list/remove_if/ . I'm cleaning up the code a bit and reposting it below. The example is about using a linked list with items, and then removing items of a given criteria. Because you don't have access to the nodes, and iterators aren't really a clean way to do this, we end up needing to pass in logic. A function predicate and a functor, not exciting yet... #include #include // A function bool single_digit(const int& value) { return (value < 10); } // A functor struct oddFunctor { bool operator() (const int& value) { return (value % 2) == 1; } }; int main() { std::forward_list mylist = { 7, 80, 7, 15, 85, 52, 6 }; mylist.remove_if(single_digit); // mylist now only contains 80 15 85 52 mylist.remove_if(oddFunctor()); // mylist now only contains 80 52 return 0; } Now let's say we want to make it even more flexible. Instead of just checking if a number is odd, we want to remove all numbers divisible by something the user specifies. Redoing that with lambdas, and adding another example. This is exciting #include #include // A messier functor struct DivisibleByFunctor { public: DivisibleByFunctor(const int divisibleValue) { this->divisibleValue = divisibleValue; } bool operator() (const int& value) { return (value % divisibleValue) == 0; } private: unsigned int divisibleValue{}; }; int main() { std::forward_list mylist = { 7, 80, 7, 15, 85, 52, 6 }; std::forward_list secondlist = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13 }; std::forward_list thirdlist = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13 }; // Lambda! The function is gone! All logic here is in one line. myList will contain 80 15 85 52 mylist.remove_if([](const int& value) {return (value < 10); }); // Lambda! The struct is gone! All logic here is in one line. myList will contain 80 52 mylist.remove_if([](const int& value) {return (value % 2) == 1; }); int divisibleValue; std::cout << "Values divisible by this should be removed: "; std::cin >> divisibleValue; // Ugly functor way. Boo! Requires a messy struct up above secondlist.remove_if(DivisibleByFunctor(divisibleValue)); // Lambda with capture of a local variable! No struct needed! All logic in one line! thirdlist.remove_if([divisibleValue](const int& value) { return (value % divisibleValue) == 0; }); return 0; }
🌐
The Pasture
thephd.dev › lambdas-nested-functions-block-expressions-oh-my
Lambdas, Nested Functions, and Blocks, oh my! | The Pasture
July 16, 2021 - As the name “lambda expressions” implies, they are also expressions, not declarations or statements. That means they can be used anywhere an expression can be used, which can come in handy for what some folks call “immediately invoked function expressions” (IIFE).
🌐
Intellipaat
intellipaat.com › home › blog › lambda expressions in c++
Lambda Expressions in C++ - Intellipaat
July 31, 2025 - Then you get the final output is 30 from lambda1 and 30 again from printing x, since x was changed by lambda2. The parameter list in a lambda expression is similar to the parameter list of a regular function, as it defines the inputs that the lambda function can easily accept.