C program storage space layout

Source: Internet
Author: User

1,Body section. This is the machine instruction part executed by c p u. Generally, body segments can be shared, so even the executed programs (such as text editors, C compilers, and s h e l) only need one copy in the memory, in addition, the body segment is often read-only to prevent the program from modifying its own instructions due to accidents.

2. initialize the data segment.This section is usually called a data segment, which contains the variables in the program that need to be assigned an initial value. For example, in the C program, description other than any function: int maxcount = 99; stores this variable in the initialization data segment as an initial value. Is it a global static variable?

3. Non-initialized data segments.This section is generally referred to as the B S segment, which is derived from an operator of the early assembler, meaning "block started by symbol (Block starting with the symbol )", before the program starts to run, the kernel initializes this segment to 0. Description outside the function: Long sum [1000]; stores this variable in non-initialized data segments.

4. Stack. The automatic variables and the information to be saved for each function call are stored in this section. Each time a function is called, its return address and caller's environmental information (such as some machine registers) are stored in the stack. Then, the newly called function automatically allocates storage space for it and temporary variables on the stack. By using the stack in this way, the C function can be called recursively.
5.It is usually used for dynamic storage allocation in the heap. Due to historical practices, the heap is located between the top of the non-initialized Data Segment and the bottom of the stack.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.