现在的位置: 首页 > 综合 > 正文

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

2012年11月25日 ⁄ 综合 ⁄ 共 574字 ⁄ 字号 评论关闭

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);

 

 运行结果如图:

 

抱歉!评论已关闭.