欢迎来到贱贱的博客

扩大
缩小

c指针点滴-指针与类型

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 //数据通信
 5 void main()
 6 {
 7     int num = 10;
 8     int *p1 = &num;
 9     int *p2 = p1;
10     printf("\n%d,%d,%d",num,*p1,*p2);
11     printf("\n%x,%x,%x",&num,p1,p2);
12 
13     *p2 = 20;
14     printf("\n%d,%d,%d",num,*p1,*p2);
15     printf("\n%x,%x,%x",&num,p1,p2);
16     getchar();
17 
18 }
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 void main1()
 5 {
 6     int num = 100;
 7     char ch = 'a';
 8     double db = 19.7;
 9     char *p1,*px;
10     int *p2;
11     double *p3;
12     printf("\n%d,%d,%d",sizeof(ch),sizeof(num),sizeof(db));
13     printf("\n%d,%d,%d",sizeof(p1),sizeof(p2),sizeof(p3));//指针都是四个字节
14     p1 = &ch;
15     px = p1;//p1 px同一个类型 无错误
16     printf("\n%c",*px);
17     //p2 = p1;
18     printf("\n%x",p1);
19     //不是同一个类型的指针 不可以任意赋值
20     //不同的类型 大小不一样 解析方式不一样
21     getchar();
22 
23 }

 

posted on 2016-10-14 13:33  L的存在  阅读(170)  评论(0)    收藏  举报

导航