手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

C语言中如何定义结构体指针

时间:2024-10-13 12:15:21

1、打开啊哈c编译器

C语言中如何定义结构体指针

2、struct student{ int score; char name[128];};//先定义一个结构体

C语言中如何定义结构体指针

3、struct student stul; stul.score = 100; strcpy(stul.name,"张三"); print熠硒勘唏f("名字:%s,分数:%d\n",stul.name,stul.score);

C语言中如何定义结构体指针

4、struct student *p;//愍荪土榷野指针 //p.score = 100;//如果用结构体指针,就不能用点运算访问结构体中的变量,要用-> //指针要注意是否是野指针或者NULL p = (struct student *)malloc(sizeof(struct student));//开辟空间 memset(p,'\0',128);

C语言中如何定义结构体指针

5、p->score = 98; strcpy(p->name,"李四"); printf("名字:%s,分数:%d\n",p->name,p->score);

C语言中如何定义结构体指针

6、printf("地址是:%p\n",p++); printf("加后地址是:%p\n",p);

C语言中如何定义结构体指针

7、运行程序

C语言中如何定义结构体指针
© 手抄报圈