Back to Module Topics1.
2.
3.
4.
4. Storage Classes
Storage Classes
Storage classes rigidly define the architectural scope (visibility), operational lifetime, and dynamic memory localization bindings associated with variables or algorithmic functions within a C program.
There are exactly 4 defined storage classes in C:
1. auto (Automatic)
- Definition: Fully represents the exact native default for localized functional variables declared internally without definitions.
- Scope: Completely local directly to the internal enclosing block
{ ... }. - Lifetime: Function execution life span; systematically deleted when the block successfully yields/exits.
- Default Initial Value: Absolute unpredictable memory "Garbage" Value.
- Storage Sector: Application Stack RAM.
void test() {
auto int a = 10; // Explicitly marked (though implicitly 'auto' naturally)
}
2. register
- Definition: Instructs the structural compiler to rigidly strive to store explicitly variables inside active CPU micro-registers functionally maximizing execution speed.
- Scope: Strictly Local structural scopes.
- Lifetime: Enclosing functional block operations.
- Default Initial Value: Application Garbage native outputs.
- Storage Sector: CPU Registers (Defaults systematically back to Stack RAM sequentially if maximum register bounds are explicitly overflowed).
- Note: The native memory reference indicator (
&) strictly cannot isolate or lock ontoregistervariables.
void loopItFast() {
register int i;
for(i=0; i<1000; i++) { }
}
3. static
- Definition: Extremely distinct scope allocation preventing internal dynamic values from natively destroying themselves recursively outside routine operational block exits.
- Scope: Syntactically local towards block parameters, BUT execution boundaries are sequentially universal to program lifetimes.
- Lifetime: Actively preserves output data consistently against terminal program closings.
- Default Initial Value: Strictly zeroes (
0). - Storage Sector: Data Memory Application Sequence Segment.
void count() {
static int c = 0; // Initializes purely functionally ONCE
c++;
printf("%d ", c);
}
// Calling count() three times prints: 1 2 3 (Data successfully retains memory bounds instead of reissuing).
4. extern (External)
- Definition: Fundamentally declares explicitly that dynamic bounds of variables are natively constructed sequentially elsewhere directly internally across files.
- Scope: Highly global logic bindings strictly spanning overarching overarching application models.
- Lifetime: Retains execution parameters directly mirroring entire application bounds.
- Default Initial Value: Syntactically strictly evaluated as (
0). - Storage Sector: Data Sector.
// File 1.c
int major_auth_code = 5055;
// File 2.c
extern int major_auth_code; // Links execution parameters sequentially over explicitly bounds globally
void display() {
printf("%d", major_auth_code);
}