typedef struct
{
int idno;
char name[max];
float cgpa;
}student;
struct node
{
student s;
Link next;
};
typedef struct node Node;
typedef Node *Link;
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为编译器不知道链接,但这是有效的
在函数'main'中:| 错误:未知类型名称'链接'|
typedef struct {
int idno;
char name[max];
float cgpa;
}student;
typedef struct node Node;
typedef Node *Link;
struct node
{
student s;
Link next;
};
Run Code Online (Sandbox Code Playgroud)
但是这里编译器在结构声明之前如何知道,因此可以定义它们的类型?
typedef struct node Node;
Run Code Online (Sandbox Code Playgroud)
告诉编译器存在一个结构类型,其中node某个地方定义了标记,这Node是该类型的另一个名称.
typedef Node *Link;
Run Code Online (Sandbox Code Playgroud)
告诉编译器这Link是另一个名字struct node *.由于所有指向结构类型的指针都需要具有相同的表示和对齐要求,因此编译器需要知道所有指针才能使用它
struct node
{
student s;
Link next;
};
Run Code Online (Sandbox Code Playgroud)