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?
Just as a brief answer, there are two usages for the
statickeyword when defining variables:1- Variables defined in the file scope with
statickeyword, 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
staticinside 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.staticvariables are usually guaranteed to be initialized to0by default.