What does static mean in ANSI-C

Sency picture Sency · Jan 2, 2011 · Viewed 45k times · Source

Possible Duplicate:
What does “static” mean in a C program?

What does the static keyword mean in C ?

I'm using ANSI-C. I've seen in several code examples, they use the static keyword in front of variables and in front of functions. What is the purpose in case of using with a variable? And what is the purpose in case of using with a function?

Answer

Roux hass picture Roux hass · Jan 2, 2011

Just as a brief answer, there are two usages for the static keyword when defining variables:

1- Variables defined in the file scope with static keyword, i.e. defined outside functions will be visible only within that file. Any attempt to access them from other files will result in unresolved symbol at link time.

2- Variables defined as static inside a block within a function will persist or "survive" across different invocations of the same code block. If they are defined initialized, then they are initialized only once. static variables are usually guaranteed to be initialized to 0 by default.