我不知道如何解释这个但是这段代码可以完美编译,但是当你运行它时,SIGSEV.请问,任何人都可以准确地告诉我哪里出错了吗?事实是我希望能够通过索引访问元素,如下所示,同时能够使用struct.
#include <stdio.h>
#include <stdlib.h>
/* This is a struct describing properties of an element */
struct element{
int age;
char* name;
};
/* This struct contains a pointer to a pointer on a element "struct element" */
struct person{
struct element** p;
int id;
};
/* Thus function initializes a struct person by allocation memory for it */
struct person* init(int size)
{
struct person* sample = (struct person* )malloc(size*sizeof(struct person));
sample->p = NULL;
sample->id = 0;
return sample; …Run Code Online (Sandbox Code Playgroud) c ×1