14、C语言中的空类型指针

来源:互联网 发布:mac在美国多少钱一支 编辑:程序博客网 时间:2024/04/30 15:45

#include <stdio.h>#include <stdlib.h>int main(){   //void * 指针类型:指向空类型或不指向确定的类型数据的指针。   void *p1=NULL;   int a=3;   p1=&a;//p1得到a的纯地址,但并不指向a,不能通过*p1操作a   //printf("p1=%d,*p1=%d\n",p1,*p1);不能使用*p1,会提示出错误。   printf("p1=%d\n",p1);   //相当于int *p2=&a;   int *p2=p1;//可以将空类型指针的值赋予另一个指针变量,由系统自动进行类型转换   printf("p2=%d,*p2=%d\n",p2,*p2);   return 0;}


程序运行结果:
p1=2686740
p2=2686740,*p2=3

Process returned 0 (0x0)   execution time : 0.467 s
Press any key to continue.