c语言 输出变量的地址,动态的观察内存的分配。

1,使用%x 来输出变量的地址

 

View Code
1 int i,j,k;
2         char ch,ch1;
3         float f1,f2;
4 
5         printf("%x   %x     %x   %x   %x  %x  %x",&i,&j,&k,&ch1,&ch,&f1,&f2);
6         scanf("%d",&i);
7         printf("%d",i);
8         printf("%x",&i);

 

2,观察指针变量地址的分配。经实验表明,指针变量的地址也和其他类型的变量地址分配类似,他们都处于同一块区域。

如下代码:

View Code
 int i,j,k;
        int *l;

        char ch,ch1;
        float f1,f2;

        l = &i;
        printf("%x  %x\n",l,&l);

        printf("%x   %x     %x   %x   %x  %x  %x",&i,&j,&k,&ch,&ch1,&f1,&f2);
        scanf("%d",&i);
        printf("%d",i);
        printf("%x",&i);

 

 运行结果如图:

 

posted on 2011-10-11 12:22  wtq  阅读(1025)  评论(0编辑  收藏  举报