A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Star_FDt78 中级黑马   /  2015-12-9 23:29  /  707 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

1.第一种方式:定义结构体的同时,定义数组
  struct Student{
      int age;
      char *name;
      int s_no;
  }stu[5];

2.第二种方式:先定义结构体,后定义数组
  struct Student stu[5];

结构体数组的初始化
1.定义结构体数组的时候进行初始化
  struct Student{
      char name[20];
      int age;
  }boys[3]={{“yu”,18},{“star”,20},{“aixing”,21}};

2.定义的同时进行初始化
struct Student girls[2]={{“fengjie”,18},{“cgx”,38}};

3.先定义后初始化,整体赋值
struct Student ds[2];
ds[0]=(struct Student){“yuaixing”,17};
ds[1]=(struct Student){“star”,24};

4.先定义结构体数组,后初始化
struct Student stu[2];
scanf(“%s”,&stu[0].name);
stu[0].age = 19;

结构体数组的遍历
for(int i=0;i<3;i++){
    printf(“name:%s,age:%d\n”,stu.name,stu.age);
}


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马