Data Segments - C Programming Tutorial
C Course / Miscellaneous / Data Segments

Data Segments

BLUF: Understanding Data Segments is a foundational part of learning C programming. This tutorial explains the core principles and syntax needed to implement this concept effectively.
Core Programming Principle: Data Segments

C provides direct access to memory and system resources. Learn how Data Segments leverages this power in the lesson below.

Memory Layout
Stack ↓ grows down
↕ Free Space ↕
Heap ↑ grows up
BSS (Uninitialized Data)
Data (Initialized Data)
Code/Text (Program Instructions)
Low Address → High Address (bottom to top)

The parts of Data segments are :

1. Data Area

It represents the non-volatile storage section where static and external variables are saved. The variables residing in this region persist throughout the program's execution lifespan.

2. Code Area

It represents the memory region exclusively accessible by function pointers. The dimensions of the code section remain constant.

3. Heap Area

C is known for its capability to support dynamic memory allocation. In C, developers rely on functions such as malloc and calloc to dynamically assign memory. Consequently, the heap region is designated to house data structures generated through dynamic memory allocation. The capacity of the heap region is flexible and is determined by the availability of free memory space.

4. Stack Area

Stack area is divided into two parts namely: initialize and non-initialize. Initialize variables are given priority than non-initialize variables.

  • All the automatic variables get memory into stack area.
  • Constants in c get stored in the stack area.
  • All the local variables of the default storage class get stored in the stack area.
  • Function parameters and return value get stored in the stack area.
  • Stack area is the temporary memory area as the variables stored in the stack area are deleted whenever the program reaches out of scope.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience