以下のコードでわかるように、親と子の 2 つの構造があります。親構造体には、子型のポインターの配列があります。プログラムが for ループに入ると、セグメンテーション エラーが発生します。私のコードに何か問題がありますか? 角括弧を使用したくない理由は、子型のポインター パラメーターを受け取る関数があり、& を使用せずにすべての子ポインターをその関数に渡したいからです。
任意の助けをいただければ幸いですありがとう
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct {
int id;
} child;
typedef struct {
child** c;
} parent;
int main(int argc, char **argv) {
int number_of_children = 5;
parent* p = (parent*)malloc(sizeof(parent));
p -> c = (child **) malloc(number_of_children * sizeof(child*));
int i;
for(i=0; i<number_of_children; i++)
p -> c[i] -> id = i;
}