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 */