Want to know in C programming language declaring a global variable without static, belongs to which storage type out of auto, extern, static, reg?
-
1easily searched, dupe of [What is default storage class for global variables?](https://stackoverflow.com/questions/3281925/what-is-default-storage-class-for-global-variables) – underscore_d Dec 18 '20 at 12:00
-
Properly speaking, C does not have any truly “global” variables. That word is not used in the C standard regarding identifiers. The standard uses different concepts of scope and linkage to describe properties of identifiers. – Eric Postpischil Dec 18 '20 at 14:42
1 Answers
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.

- 301,070
- 26
- 186
- 335