我从一本C++书中读到,在ANSI C中,const值是全局的吗?但如果我声明一个const变量main()然后它将在本地作用域,那么我们怎么能说const是全局的呢?
C中没有全局词法范围,但有一个文件范围.const对象的限定不影响其范围.
#include <stdio.h>
int a = 0; // file scope
const int b = 0; // file scope
int main(void)
{
int x; // block scope
const int y; // block scope
}
Run Code Online (Sandbox Code Playgroud)