有3個學生的信息,放在結構體數組中,要求輸出全部學生信息


#include<stdio.h>
struct  Student//聲明結構體類型struct student 
{  int  num;
   char name[20];
   char sex;
   int  age;
};
struct  Student  stu[3]={{10101,"LiLin",'M',18},{10102,"ZhangFang",'M',19},{10104,"WangMing",'F',20}};//定義指向struct student結構體變量的指針變量 
int  main()
{struct  Student  *p;//
printf("No.Name     sex  age\n");
for(p=stu;p<stu+3;p++)
printf("%5d%-20s%2c%4d\n",p->num,p->name,p->sex,p->age);//輸出結果 
return 0;
}

No.Name sex age
10101LiLin M 18
10102ZhangFang M 19
10104WangMing F 20

--------------------------------
Process exited after 0.2853 seconds with return value 0
請按任意鍵繼續. . .


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM