如何访问结构中的结构数组

时间:2015-07-31 10:18:53

标签: data-structures union

struct students
{
   char name[256];
   int Roll_number;
};

struct colleges 
{
   char name[256];
   Student students[100];
};

如何访问学生[0] .name,我尝试使用 - >和。运营商是无法访问的

2 个答案:

答案 0 :(得分:0)

#include <stdio.h>
struct students {
    char name[256];
    int Roll_number;
};

struct colleges {
    char name[256];
    struct students students[100];
};
int main(void)
{
    struct colleges c = { };
    printf("%s\n", c.students[0].name);
    return 0;
}

答案 1 :(得分:0)

结构内的结构:嵌套结构

  1. 在另一个结构中写入的结构称为两个结构的嵌套。
  2. C编程语言允许使用嵌套结构。
  3. 我们可以在另一个结构中写一个结构作为另一个结构的成员。
  4. 作为另一个结构的成员

    enter image description here

    enter image description here

相关问题