通過指向結構體變量的指針輸出結構體變量中 成員信息


#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