Skip to content

Instantly share code, notes, and snippets.

@johnpena
Created February 15, 2011 03:30
Show Gist options
  • Save johnpena/827052 to your computer and use it in GitHub Desktop.
Save johnpena/827052 to your computer and use it in GitHub Desktop.
static vs automatic variables in c
#include <stdio.h>
void foo()
{
static int i = 1;
int j = 1;
i++; //
printf("i: %d, ", i);
j++; //
printf("j: %d\n", j);
}
int main()
{
foo(); //i: 2, j: 2
foo(); //i: 4, j: 2
foo(); //i: 6, j: 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment