Memory layout in c programming

07 Sep 2022 Balmiki Mandal 0 C Programming

Step-by-step Guide: Memory Layout of the C programming 

whenever we write some program suppose program. c  and press hit enter to compile the code then generate a program.exe file (for windows)   or ./a.out file (for Linux) that executable file for the program.c takes four stages in  memory we simply called the memory layout of the c programming 

Stages are Respectively

  1. Stack Section
  2. Heap Section
  3. Data Section
  4. Code Section

1. Stack section in c:

The stack section is called simply temp memory, stacks section contains auto variables, function return, and formal arguments.

In computing, a stack is a section of memory used to store data temporarily during program execution. It is a data structure that follows the Last-In-First-Out (LIFO) principle, which means that the most recently added item to the stack is the first one to be removed.

 

2. Heap section in c:

The heap section is used for Dynamic memory allocation also called run-time memory allocation

In C programming language, the heap section is a region of memory that is used to allocate memory dynamically at runtime. The heap section is also known as the free store, and it is managed by the operating system and the C runtime library.


3. Data Section:

In C programming language, the data section is a region of memory that contains static and global variables. Static variables are variables that are declared with the static keyword, and they are initialized once when the program is loaded into memory. Global variables are variables that are declared outside of any function, and they are also initialized once when the program is loaded into memory.

The data section is used for static variables and extern variables and also function symbols.

 

4. Code Section:

In C programming language, the code section, also known as the text section, is a region of memory that contains the compiled machine code for the program's instructions and functions. The code section is a read-only section of memory, which means that the contents of the section cannot be modified during program execution

Code Section Contains Upcode 

Enroll Now:

C-Programming From Scratch to Advanced 2023-2024] "Start Supercharging Your Productivity!"

Contact Us:

  • For any inquiries, please email us at [[email protected]].
  • Follow us on insta  [ electro4u_offical_ ] for updates and tips.

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.