One, the stack area address growth direction
To verify that the stack area is opening up or down, the operation of the first pressure variable A and pressure variable B, if the first address of a is larger than the first address of B to explain the opening downward, if the first address of B is larger than the first address of a, then the opening up, the following code to verify:
#include "stdio.h"
#include "stdlib.h"
int main () {
int A;
int b;
printf ("&a:%d\n", &a);
printf ("&b:%d\n", &b);
System ("pause");
return 0;
}
Debug output results:
Output results under release:
Can see two versions, A's first address is always larger than the first address of B, basically can determine the stack area openings downward, some people's release version may appear the first address of a is always smaller than the first address of B, in fact, this also does not matter.
stack area opening downward is mainly convenient to avoid stack overflow problem, define a starting maximum value, and then open the stack downward, until 0 can not press stack.
Second, the address of the heap area growth direction
#include "stdio.h"
#include "stdlib.h"
int main () {
int *a= (int*) malloc;
int *b = (int*) malloc (a);
printf ("A:%d\n", a);
printf ("B:%d\n", b);
System ("pause");
return 0;
}
Output results:
You can see that the heap area is open up.
Third, the growth direction of BUF address
Regardless of the opening direction of the stack area, the growth direction of the BUF address in the stack space is upward, if the growth direction downward, to BUF first address + 1 o'clock will not run to other memory space.
Third, summary
1, the stack area openings downward (general situation);
2, the heap area openings upward;
3, the address growth direction of the stack area and the growth direction of the BUF address are two completely different concepts.