c - C中的静态和外部有什么区别?

标签 c

staticextern 在 C 中有什么区别?

最佳答案

来自 http://wiki.answers.com/Q/What_is_the_difference_between_static_and_extern :

The static storage class is used to declare an identifier that is a local variable either to a function or a file and that exists and retains its value after control passes from where it was declared. This storage class has a duration that is permanent. A variable declared of this class retains its value from one call of the function to the next. The scope is local. A variable is known only by the function it is declared within or if declared globally in a file, it is known or seen only by the functions within that file. This storage class guarantees that declaration of the variable also initializes the variable to zero or all bits off.

The extern storage class is used to declare a global variable that will be known to the functions in a file and capable of being known to all functions in a program. This storage class has a duration that is permanent. Any variable of this class retains its value until changed by another assignment. The scope is global. A variable can be known or seen by all functions within a program.

关于c - C中的静态和外部有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3684450/

相关文章:

c - osx 构建失败

c - 带函数指针参数的函数指针

c++ - libstdc++-6.dll 问题

c++ - 为什么 C++ 初始分配比 C 大得多?

c - 如何在 C 语言的缩小示例中使用 __extension__ 和 __typeof__?

c++ - 为什么我的电源运算符 (^) 不起作用?

c++ - wchar* 和打印它的问题 C

c - 在 C OpenMP 中并行化函数

c - TCP:建立TCP连接

c++ - 从 C++ 拦截 Fortran STOP