- 为什么 c 语言有static function
c++ class 有 static function 能理解， 代表不用实例化类也可以调用的函数
c 并没有类的概念， static function 是什么意思 ？
解释 ： In C, functions are global by default. The “static” keyword before a function name makes it static.
Unlike global functions in C, access to static functions is restricted to the file where they are declared.
/* Inside file1.c */
/* Iinside file2.c */
- static variable
1) A static int variable remains in memory while the program is running. A normal or auto variable is destroyed when a function call where the variable was declared is over.
2) Static variables are allocated memory in data segment, not stack segment. See memory layout of C programs for details.
3) Static variables (like global variables) are initialized as 0 if not initialized explicitly. For example in the below program, value of x is printed as 0, while value of y is something garbage. See this for more details.
4) In C, static variables can only be initialized using constant literals. For example, following program fails in compilation. See this for more details.