1 #include <stdio.h>
2 void main()
3 {
4 int i=4;
5 int*p=&i;
6 //int *p=(int *)4;
7 printf("%d\n",*p);
8 printf("%p\n",p);
9 *p=12;
10 printf("%d\n",*p);
11 printf("%p\n",p);
12 getchar();
13 return;
14 }
当为 int *p=(int *)4的时候会报错。
因为 4在内存中没有相应地址映射,p指向的是非法地址。
ps:在对指针操作时,如果拿不住,还是if()一下比较安全。
快捷操作:
坚其志,苦其心,劳其力,事无大小,必有所成。
@如有侵权,请作者本人尽快与我(chrayo#163.com)联系,我将及时删除侵权内容。