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;
}
相关文章
相关标签/搜索