C Memory Division Text (code segment), Data and BSS

wahyu eko hadi saputro
2 min readFeb 16, 2023

--

In general C memory is divided into some part, that are :

  1. Code / Text segment (i.e. instructions)
  2. Data (Initialized data segment)
  3. Uninitialized data segment (bss)
  4. Heap
  5. Stack

For more info refer to my medium : https://wahyu-ehs.medium.com/memory-management-on-c-programming-ce30135cfbcb

example of memory C layout
example of memory c layout

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;
}
compile the code
inspect the code by using size command

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/

--

--