局部变量除了static修饰的放在静态区,其余全部栈区(包括const修饰的常量、字符串常量)。全局变量和static修饰的全局变量放在静态区,const修饰的放在常量池,字符串常量放在静态区。
char q[] = "where is the address";
static int x= 9;
int y =6;
const int z =1;
int main(int argc, char const *argv[])
{
const char m[] = "address";
char s[] = "address in";
static int a= 80;
int b =0;
const int c =3;
printf("顺序打印地址\n");
printf("%p\n",q);
printf("%p\n",&x);
printf("%p\n",&y);
printf("%p\n",&z);
printf("\n");
printf("%p\n",m);
printf("%p\n",s);
printf("%p\n",&a);
printf("%p\n",&b);
printf("%p\n",&c);
return 0;
}
打印结果:
顺序打印地址
0x5e19e2e09010
0x5e19e2e09028
0x5e19e2e0902c
0x5e19e2e07004
0x7fffb73f9cd5
0x7fffb73f9cdd
0x5e19e2e09030
0x7fffb73f9ccc
0x7fffb73f9cd0
若有不同欢迎指正!!!