- //结构体数组
- //定义一个结构体
- struct student {
- char *name;
- int age;
- double score;
- };
- //定义结构体数组
- struct student stu[3] = {
- {"小红",22,98},
- {"小明",23,96},
- {"老王",42,58}
- };
- //用for循环输出结构体
- int i;
- for(i = 0; i<3; i++){
- printf("姓名:%s\t年龄:%d\t分数:%.2f\n",stu[i].name,stu[i].age,stu[i].score);
- }
复制代码
|
|