Stack Area: Staging Area
#include <iostream>using namespacestd; #include<stdio.h>intMain () {intA= -; intb=Ten; cout<<"/********************************/"<<Endl; printf ("%d\n",&a); printf ("%d\n",&b); if(&a>&b) {cout<<" Down"<<Endl; }Else{cout<<" up"<<Endl; } intc[Ten]; cout<<"/********************************/"<<Endl; for(intI=0;i<Ten; i++) {C[i]=i; } cout<<"/********************************/"<<Endl; for(intj=0;j<Ten; j + +) {printf ("%d\n",&C[j]); } cout<<"/********************************/"<<Endl; float*p=NULL; Double*q=NULL; printf ("%d\n", p); printf ("%d\n", q); printf ("%d\n",&p); printf ("%d\n",&q); cout<<"/********************************/"<<Endl; return 0;}
Conclusion: &a>&b. Define the variable a first, and then define the variable B. Variable A variable b is in the staging area. So the stack grows downward. For the array address as the subscript grows larger, this is due to the growth direction of the stack and memory space buf storage direction is two different concepts.
Heap Area:
#include <iostream>using namespacestd; #include<stdio.h>#include<stdlib.h>intMain () {Char*p=NULL; Char*q=NULL; P=(Char*)malloc( -*sizeof(Char)); Q=(Char*)malloc( -*sizeof(Char)); printf ("\n%d\n",sizeof(Char)); printf ("%d\n",&p); printf ("%d\n",&q); printf ("\np[0]:%d", &p[0]); printf ("\np[1]:%d", &p[1]); printf ("\nq[0]:%d", &q[0]); printf ("\nq[1]:%d", &q[1]); if(p!=NULL) { Free(P); } if(q!=NULL) { Free(q); } return 0;}
Conclusion: the P pointer and malloc area are defined first, and the Q pointer and malloc area are defined. In the heap area P[0] larger than q[0]. and p[1] larger than p[0]. It is known that the heap grows upward.
C + + stack growth direction