A global variable in C is a variable declared outside of all functions and blocks, possessing file scope and static storage duration. It is accessible to any function defined within the same translation unit from the point of its declaration downward.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Technical Characteristics
Scope and Visibility Global variables possess file scope. Their visibility begins at the exact line of declaration and extends to the end of the source file. If a local variable within a function shares the same identifier as a global variable, the local variable shadows the global variable within that block. Storage Duration and Lifetime Global variables have static storage duration. Memory for these variables is allocated once when the program is loaded into memory and is deallocated only when the program terminates. Their values persist across multiple function calls. Initialization Rules- Implicit Initialization: If not explicitly initialized by the programmer, the C compiler automatically initializes global variables to zero (
0for integers,0.0for floats,\0for characters, andNULLfor pointers). - Constant Expressions: Explicit initialization of a global variable must be done using a constant expression. You cannot initialize a global variable with a value evaluated at runtime, such as a function return value or another variable.
extern keyword.
static keyword, which changes its linkage from external to internal linkage.
Memory Layout
Global variables are stored in specific segments of the program’s virtual memory space, separate from the stack and heap:
- Data Segment: Houses global variables that are explicitly initialized to a non-zero value.
- BSS (Block Started by Symbol) Segment: Houses global variables that are either uninitialized or explicitly initialized to zero. The OS zeroes out this memory segment before program execution begins.
Master C with Deep Grasping Methodology!Learn More





