I know what is the purpose of using static variables in an object oriented language, still, I don't understand what is the meaning of using the "static" keyword in C. Can someone explain it to me?
相关问题
- Multiple sockets for clients to connect to
- Keeping track of variable instances
- What is the best way to do a search in a large fil
- How to get the maximum of more than 2 numbers in V
- glDrawElements only draws half a quad
The value that a static variable has upon leaving a function is the same value that variable will have the next time the function is called.
A static function can be called only from within the same file that the function appears.
On a function or global variable,
static
makes the function or global variable local to that file; other files cannot access that function or global variable by that name (but they can access it if you give a pointer to it away).On a local variable, it makes it act as if it was a global variable, but is only accessible within that function (unless, again, you give a pointer to it away).