Reputation: 57
I read from a C++ book that In ANSI C, const values are global? but if i declare a const variable in main()
then it will be locally scoped then how we can say that const are global?
Upvotes: 2
Views: 267
Reputation: 145829
There is no global lexical scope in C but there is a file scope. The const
qualification of an object does not affect its scope.
#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
}
Upvotes: 5