Memory Layout of a C Program
Memory Layout of a C Program
3. Stack Segment
4. Heap Segment
We can see that the data segment contains 1532 bytes and the BSS
segment contains 112 bytes.
Now let’s change the code and check the size again:
• Since it's now initialized, we expect it to move from the BSS segment
to the data segment, right?
Why is that?
✅ That’s why the variable is still stored in the BSS segment, not in the
data segment.
Now you can clearly observe that the data segment size increased by 4
bytes while the BSS segment size decreased by 4 bytes. This change
occurred because the variable i was initialized with a non-zero value, which
means it must be stored in the initialized data segment instead of the BSS.
As a result, memory allocation shifted from BSS to the data segment.