user2487315
user2487315

Reputation: 57

In ANSI C,const values are global?

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

Answers (1)

ouah
ouah

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

Related Questions