有关C语言 结构 问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 19:29:43
struct student
{
char name[80];
struct student next;
}
请问以上的代码,错在哪儿里?书上说有两处,可我只找到一处。。
struct student next;
这个为什么next要是指针的形式,不是指针行不行?

当然不行,编译器在编译程序时,必须确切知道所有数据类型的大小,如果你不加指针的话,这个结构就成了一个矛盾体了,因为出现了这样的情况,即
sizeof(student)=80+sizeof(student),这是不可能成立的.
加了指针的话,因为在一个系统中,指针的大小是固定的,一般是32位,即4字节,student的大小就能确定了.

我不是很清楚你想定义什么struct student next;
但是我想应该是指针 改为 struct student *next;就OK了
而且结构体定义之后要有";"的

如果不是指针的话 不用这种定义形式
比如你想定义一个整形变量 就直接这样写就可以了
struct student
{
char name[80];
int a;
};
而struct student *next;是定义一个student类型的指针

应该是:
struct student
{
char name[80];
struct student *next;
};

首先在花括号那里就少了个分号。。这个事结构体必须得
还有就是struct student next;是指针才对,不然会造成运行错误,,,

struct student
{
char name[80];
struct student next;
}

1。}后面需要分号
2。struct student next;因为这个时候struct student的大小不能确定,是个无线循环的结构
改成struct student *next;这里next是指针,大小是确定的,不会造成无线循环

1. 最后加分好
2. struct student* next;