int add(int a,int b)
{
return a+b;
}
//全局区
int a1 = 1; //全局变量
static int a2=2;//全局静态变量
const int a3=3; //全局常量
main()
{
int b1=4;
static b2=5;
const b3 =6;
int *p1=malloc(40);
printf("a1:%p\n",&a1);
printf("a2:%p\n",&a2);
printf("a3:%p\n",&a3);
printf("b1:%p\n",&b1);
printf("b2:%p\n",&b2);
printf("b3:%p\n",&b3);
printf("p1:%p\n",p1);
printf("main:%p\n",&main);
printf("add:%p\n",&add);
while (1);
}
运行结果:a1:0x80497e4 //全局变量--------在全局区a2:0x80497e8 //全局静态变量--在全局区a3:0x80485f4 //全局常量--------在代码区b1:0xbfa06c28 //局部变量--------在局部栈b2:0x80497ec //局部静态变量--在全局区b3:0xbfa06c24 //局部常量--------在局部栈p1:0x84c1008 //指针--------------在堆main:0x8048432 //在代码区add:0x8048424 //在代码区