Skip to content

Instantly share code, notes, and snippets.

@catharinejm
Created September 6, 2011 02:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save catharinejm/1196418 to your computer and use it in GitHub Desktop.
Save catharinejm/1196418 to your computer and use it in GitHub Desktop.
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
5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment