static Keyword
Limits Visibility ( for Functions / Globals) to one file and extends Lifetime (for Local Variables) to the entire program.
Global Logic
Control: Visibility
Basic Concept
Restricts External Linkage (Public) to Internal
Linkage (Private).
Mechanism
Encapsulates variables/functions within a single source file. Prevents
cross-module access via
extern.Local Logic
Control: Lifetime
Basic Concept
Changes Automatic Lifetime (Stack) to Static
Lifetime (Persistent).
Mechanism
Variable retains its state throughout program execution. Initialized only once
during program loading.
The Silicon Reason
Memory Placement
Static data resides in .data or .bss
segments. NOT on the Stack.
Technical Reason
Segments are allocated at load-time and survive until termination, unlike
Stack frames which are cleared on return.