/* * static.c - illustrates the use of auto variables, with `static`. * * Code taken from pg. 336 (Program 7.2) (Bronson) * "First Book on ANSI C" * * CS50 */ #include <stdio.h> void testauto(); // function prototype int main() { int count; // create the auto variable count for (count = 1; count <= 3; count++ ) testauto(); return 0; } /* The variable num in teststat() is only set to zero once. The value set by the local scope static variable num detains its value when teststat() returns.*/ void testauto() { static int num = 0; // num is a local static variable printf("The value of the automatic variable num is %d\n", num); num++; }