{C language} stack, stack, and stack sp

Source: Internet
Author: User

STACK: a main storage area of the "back-to-first-out" (LIFO), located in the stack segment, using the SS segment register to record its segment address. It has only one entrance, that is, the top of the current stack, and the top of the stack is a small end (low end), which is specified by the stack pointer register sp. The stack has two basic operations in the unit of words, corresponding to two basic commands: The push command in the stack and the pop command in the stack.

Stack Zone(Stack)-the compiler automatically assigns release, stores the parameter values of the function, and values of local variables. The operation method is similar to the stack in the data structure. That isToo much vomit. For example, when calling a function.

Heap Area(HEAP)-generallyProgramMembers are assigned to release the program. If the programmer does not release the program, it may be recycled by the OS at the end of the program. Note that it is different from the heap in the data structure. The allocation method is similar to the linked list. For example, the malloc Function

Global Zone(Static)-the storage of global and static variables is put together, and the initialized global and static variables are in one area, uninitialized global variables and uninitialized static variables are in another adjacent area. The program is released by the system.

Text Constant Area-The constant string is placed here and is released by the system after the program ends.

The initialized data segment (. Data) contains the global variables explicitly defined in the program and static variables.

Non-initialized data segments (. BSS) do not provide global variables and static variables that clearly define the initial values.

ProgramCodeArea (code segment)-stores the binary code of the function body.
Queue: first-in-first-out, eat too much.

Although the stack is called a connection, they still have a lot of difference. The connection is only due to historical reasons.

If you wantIn-depth study cThe best thing to do is to viewCompiled assemblyCode to view its specific operations, of course, this is only a personal research, if you want to know the celebration of various library functions, You can queryC Language Library source code(Classic and concise ).Read moreNow!

Generally, the compiler divides the memory into three parts:Static storage area, stack, and stack.

Static storage ZoneStores global and static variables,

Stack StorageCall function-related variables, addresses, etc,

Heap StorageDynamically generated variables in CIs released by the malloc and free operations.Storage spaceIn C ++, it refers to the functions of the new and delete operators.Storage Area.

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.