c语言结构体保存并输出学生信息


最近在学习数据结构,巩固下c语言。

#include<stdio.h>
/*定义结构体student并设置别名stud*/

/*typedef struct student{
    int num;
    char *name;
    int score;
}stud;
*/

/*同上面4行代码*/
struct student{
    int num;
    char *name;
    int score;
};
typedef struct student stud;


stud stu[3] = {
    {1026,"Jack",100},
    {1028,"Michael",80},
    {1030,"Nice",30}
};

int main()
{
    int i;
    for(i=0;i<3;i++)
    {
        printf("%d,Name:%s,score:%d\n",stu[i].num,stu[i].name,stu[i].score);
    }
    return 0;
}

 


免责声明!

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



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