Next: Constants Up: Constant and Variable Previous: External Variables

Static Variables

Another class of local variable is the static type. A static can only be accessed from the function in which it was declared, like a local variable. The static variable is not destroyed on exit from the function, instead its value is preserved, and becomes available again when the function is next called. Static variables are declared as local variables, but the declaration is preceeded by the word static.


static int counter;
Static variables can be initialised as normal, the initialisation is performed once only, when the program starts up.


craa27@strath.ac.uk
Tue Jan 17 11:40:37 GMT 1995