簡體   English   中英

如何訪問結構中的結構數組

[英]how to access array of structure within a structure

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

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

如何訪問 student[0].name,我嘗試使用 -> 和 . 操作員不可訪問

#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. 寫在另一個結構中的結構稱為兩個結構的嵌套。
  2. C 編程語言中允許使用嵌套結構。
  3. 我們可以在另一個結構中編寫一個結構作為另一個結構的成員。

作為另一個結構的成員

在此處輸入圖片說明

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM