Create a gist now

Instantly share code, notes, and snippets.

inner function closure in C
#include <stdlib.h>
#include <stdio.h>
int(*outer(int val))() {
int inner() {
return val;
return inner;
int main() {
printf("%d\n", outer(5)());
return 0;
$ gcc -fnested-functions -o closure closure.c
$ ./closure

But I can't help thinking inner had been freed before it was called and I got lucky...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment