码迷,mamicode.com
首页 > 其他好文 > 详细

c指针点滴-指针与类型

时间:2016-10-14 14:21:34      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

 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 }

 

c指针点滴-指针与类型

标签:

原文地址:http://www.cnblogs.com/lanjianhappy/p/5960084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!