Created
February 15, 2011 03:30
-
-
Save johnpena/827052 to your computer and use it in GitHub Desktop.
static vs automatic variables in c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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