Skip to content

Instantly share code, notes, and snippets.

@pix0r
Created May 24, 2014 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pix0r/a670efa812a7f69fec33 to your computer and use it in GitHub Desktop.
Save pix0r/a670efa812a7f69fec33 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int test() {
static int val = 0;
val += 1;
return val;
}
int main() {
printf("val: %d\n", test());
printf("val: %d\n", test());
printf("val: %d\n", test());
printf("val: %d\n", test());
printf("val: %d\n", test());
return 0;
}
@pix0r
Copy link
Author

pix0r commented May 24, 2014

mike@Mike-MBP2:~$ ./static
val: 1
val: 2
val: 3
val: 4
val: 5

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