Which of the storage class given in options is the default storage class of all the global...
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Which of the storage class given in options is the default storage class of all the global variables?
Show answer & explanation
Global variables have external linkage by default, meaning they are visible across translation units unless explicitly declared as static. The extern storage class is the implicit default for all global variables in C/C++, allowing them to be accessed from other source files. Register, Auto, and Static either don't apply to globals (register, auto) or explicitly restrict scope to a single translation unit (static).
Step-by-step Derivation:
In C/C++, storage classes define scope, lifetime, and visibility:
- Register – For local variables; requests CPU register allocation. Not applicable to globals.
- Auto – For local variables with automatic storage duration. Not applicable to globals.
- Static – Restricts scope to current translation unit (internal linkage). Explicitly declared, not default.
- Extern – Declares external linkage, allowing access across translation units. This is the implicit default for all global variables.
Example:
int global_var; // Implicitly extern, visible in other files
extern int global_var; // Explicit declaration, same as above
static int global_var; // Now restricted to this file only
Global variables without explicit storage class qualifiers default to extern.