Global variable belongs to which storage type in c?

202 Views Asked by At

Want to know in C programming language declaring a global variable without static, belongs to which storage type out of auto, extern, static, reg?

1

There are 1 best solutions below

0
On

Such a variable has external linkage and static storage duration. It may be initialized by a constant expression or string literal.

From the C Standard (6.2.2 Linkages of identifiers)

5 If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern. If the declaration of an identifier for an object has file scope and no storage-class specifier, its linkage is external.

and (6.2.4 Storage durations of objects)

3 An object whose identifier is declared without the storage-class specifier _Thread_local, and either with external or internal linkage or with the storage-class specifier static, has static storage duration. Its lifetime is the entire execution of the program and its stored value is initialized only once, prior to program startup

and at last (6.7.9 Initialization)

4 All the expressions in an initializer for an object that has static or thread storage duration shall be constant expressions or string literals.