Function pressure stack sequence-C

Source: Internet
Author: User

Basic knowledge:

After a program runs, it has five areas in the memory.
1. Code Area
This is very simple. To execute the code, you must load it into the memory. We don't have to worry about it.

2. Text Constant Area
When we define a string like this, it is in the text constant area:
Char * S1 = "Hello, world ";
Char * S2 = "Hello, world ";
If (S1 = S2)
Printf ("S1 and S2 point to the same string in the text Constant Area ");

Here, S1 and S2 point to the same string

3. static storage Zone
Global variables. Static variables are placed in this region. In fact, global variables are also static.

When there are programs in the above 1, 2, and 3 regions, they will be opened up.

4. Stack
Local variables are in the stack. In addition, the parameters used for function calling are also in the stack.

5. Heap
Malloc or new memory is stored in the heap. You need to clear the memory by the programmer.


# Include <stdio. h> # include <stdlib. h> # include <string. h>/* The pressure stack sequence is from right to left, from top to bottom */INT fun (int I, char * s) {/* the compiler is equivalent to int A; int B; */int A, D; printf ("& s = 0x % 08x \ n", & S); printf ("& I = 0x % 08x \ n ", & I); printf ("& F = 0x % 08x \ n", & fun); printf ("& A = 0x % 08x \ n", & ); printf ("& D = 0x % 08x \ n", & D);}/* [email protected] test_class] #. /. out & s = 0xbff4b284 & I = 0xbff4b280 & F = 0x08048404 & A = 0xbff4b26c & D = 0xbff4b268 */intmain () {int I = 0x22222222; char * s = "aaaa"; fun (I, S );}


/* Stack -- Stack from high address to low address -- Stack from low address to high address, for example */






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.