c语言指针与结构体
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 struct mydata 5 { 6 int num; 7 char str[200]; 8 }; 9 10 void main1() 11 { 12 /*int a; 13 int *p;*/ 14 struct mydata *p;//p存储地址 struct mydata决定了大小还有如何解析 15 struct mydata md;//实例化结构体 16 md.num = 89; 17 sprintf(md.str,"ppp"); 18 printf("\nmd.num=%d,md.str=%s",md.num,md.str); 19 20 printf("%d",sizeof(p));//任何指针都是4个字节 21 p = &md;//结构体指针初始化 22 23 //结构体访问方式两种 (*p).和p-> 24 printf("\n(*p).num=%d,(*p).str=%s",(*p).num,(*p).str); 25 printf("\nmd.num=%d,md.str=%s",p->num,p->str); 26 27 28 getchar(); 29 }