C Memory Division Text (code segment), Data and BSS
In general C memory is divided into some part, that are :
- Code / Text segment (i.e. instructions)
- Data (Initialized data segment)
- Uninitialized data segment (bss)
- Heap
- Stack
For more info refer to my medium : https://wahyu-ehs.medium.com/memory-management-on-c-programming-ce30135cfbcb
create c file with a name is hello-world.c, then put the below code into the file.
#include <stdio.h>
int globalOne;
int globalTwo;
int init1 = 1;
int main(){
int a=0;
int b=0;
return 0;
}
Text segment (instruction code) = 16880 byte
Data = 1636 byte
Bss (Uninitialized data segment) = 124 byte
Dec (decimal) = text + data + bss = 18640 byte
Text segment (instruction code) : it’s include our code instruction and constant
Data : data is for initialized global variable, from above code is int init1 = 1;
Bss : for uninitialized global variable, from above code is int globalOne;
Source :
https://www.scaler.com/topics/c/memory-layout-in-c/