#include <stdio.h>
struct Student {
char *name;
int ival;
char *chval;
};
struct Student stu[] = {
{
.name = "JIM",
.ival = 5,
.chval = "ARM",
},
{
.name = "GReen",
.ival = 6,
.chval = "X86",
},
};
int main(){
//Way:1
printf("name = %s, ival = %d, chval = %s\n",stu[0].name,stu[0].ival,stu[0].chval);
printf("name = %s, ival = %d, chval = %s\n",stu[1].name,stu[1].ival,stu[1].chval);
//结构体元素个数
printf("count = %ld\n",sizeof(stu) / sizeof(struct Student));
//Way:2
int i;
for(i = 0; i < (sizeof(stu) / sizeof(struct Student)); i++){
printf("name = %s, ival = %d, chval = %s\n",stu[i].name,stu[i].ival,stu[i].chval);
}
}