What is a Variable in Memory?
Declaration, Definition, and RAM byte allocation
In C, a Variable is simply a convenient human-readable label given to a specific block of bytes in the computer's RAM. When you declare a variable, the compiler reserves memory cells of the requested data type size.
variables.c
int age; // 1. Declaration: Reserves 4 bytes on the Stack (Contains uninitialized garbage!) age = 21; // 2. Assignment: Writes binary 00000000 00000000 00000000 00010101 into those 4 bytes int score = 100; // 3. Initialization: Declaration + immediate assignment in one line
🚨
The Uninitialized Variable Trap (Garbage Values)
In C, local variables inside functions are NOT automatically set to zero. They hold whatever random leftover bits existed in that RAM slot before. Always initialize your variables before reading them!