Obviously, i and j are used as global variables in the program's static storage area; this area is applied for when the program starts and is not released during the entire program running. .
x and p are local variables allocated on the call stack . It is allocated when f() is called and released when it returns (pops off the stack).
fAs a function, the code segment is stored in memory. The code segment is read into memory when the program starts and remains unchanged throughout the program.
The memory pointed to by
p is allocated on the heap. The essence of "heap" is the space that the system dynamically allocates to memory - the program treats a section of space dynamically applied for from the system as a "heap" and provides flexible allocation functions such as malloc(). The operating system actually only knows that a section of memory has been requested by the program, but does not know that the usage model of this memory is "heap".
f:.text segment, i:.data segment, j:.bss segment, x,p:stack, x and p are local variables, stored on the stack on, but the memory space pointed to by p is on the heap.
Obviously,
i
andj
are used as global variables in the program's static storage area; this area is applied for when the program starts and is not released during the entire program running. .x
andp
are local variables allocated on the call stack . It is allocated whenf()
is called and released when it returns (pops off the stack).
The memory pointed to byf
As a function, the code segment is stored in memory. The code segment is read into memory when the program starts and remains unchanged throughout the program.p
is allocated on the heap. The essence of "heap" is the space that the system dynamically allocates to memory - the program treats a section of space dynamically applied for from the system as a "heap" and provides flexible allocation functions such asmalloc()
. The operating system actually only knows that a section of memory has been requested by the program, but does not know that the usage model of this memory is "heap".f:.text segment,
i:.data segment,
j:.bss segment,
x,p:stack,
x and p are local variables, stored on the stack on, but the memory space pointed to by p is on the heap.
i,j are in the static area, x is in the stack area, and the content of p is in the heap area
sampe—>sample is->are
Please read the following two articles, it will be explained very clearly
ij is in the heap
xp is in the stack
http://segmentfault.com/a/1190000002575242
http://m.blog.csdn.net/blog/zhoucoolqi/7540612