/* static.c - tests static variables * * Example for CS 313 * * There are three variables 'n', all static, and all different. */ #include int n=0; /* global n, starting at 0 */ void a() { static int n=0; /* a's n, starting at 0 */ n++; printf("a: %d\n", n); } void b() { static int n=5; /* b's n, starting at 5 */ n++; printf(" b: %d\n", n); } void c() { n++; printf(" c: %d\n", n); } int main() { a(); b(); c(); a(); a(); b(); c(); a(); b(); c(); c(); c(); c(); return 0; } /* output: a: 1 b: 6 c: 1 a: 2 a: 3 b: 7 c: 2 a: 4 b: 8 c: 3 c: 4 c: 5 c: 6 */