通过指向结构体变量的指针输出结构体变量中 成员信息


#include<stdio.h>
#include<string.h>
int  main()
 {struct  Student
   { long  num;
     char  name[22];
     char  sex;
     float score;
   };
   struct  Student  stu_1;//定义struct  student类型的变量stu1 
   struct  Student  *p;//定义指向struct student类型数据的指针变量p 
   p=&stu_1;//p指向stu1 
   stu_1.num=10101;//对结构体的变量成员赋值 
   strcpy(stu_1.name,"LiLin");//用字符串复制函数给stu1.name赋值 
   stu_1.sex='M';
   stu_1.score=89.5;
   printf("No.:%ld\nname:%s\nsex:%c\nscore:%5.1f\n",stu_1.num,stu_1.name,stu_1.sex,stu_1.score);//输出结果 
   printf("No.:%ld\nname:%s\nsex:%c\nscore:%5.1f\n",(*p).num,(*p).name,(*p).sex,(*p).score);
   return 0;
 }

No.:10101
name:LiLin
sex:M
score: 89.5
No.:10101
name:LiLin
sex:M
score: 89.5

--------------------------------
Process exited after 0.238 seconds with return value 0
请按任意键继续. . .


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM