以下用法不都一样吗,为什么会报错?

main()
{
struct
{
int num;
} ;
struct aa ;
aa.num = 0;
}
为什么 会报错??
而这样又不会:
main()
{
typedef struct
{
int num;
} student;
student aa ;
aa.num = 0;
}
不都一样意思吗?搞不懂.

哔哔one
浏览 182回答 3
3回答

慕的地8271018

struct{int num;} ;这种写法不对的。struct是个关键字,单独存在不能表示结构体,struct student{int num;} ;这样才对,这里的struct student你可以理解为类似int的一种数据类型,只不过这种数据类型是你自己定义的,里面存放的数据有特定的规格。

哈士奇WWW

如果按照你的思路,定义两个结构体:struct { int num; } ;struct { int value; } ;struct a; // 你觉得这里的a是上面的哪一个结构体呢?所以结构体是要有名字的,或者定义的同时声明变量:1)struct a{ int num; } ;struct b{ int value; } ;struct a aa;struct b bb;2)typedef struct { int num; }a ;typedef struct { int value; }b ;a aa;b bb;3)struct { int num; } aa;struct { int value; } bb;

慕少森

肯定不是一个意思啊,上面的那个结构体连名字都没有。改成下面这样才是一样的main(){struct student{int num;} ;struct student aa ;aa.num = 0;}
打开App,查看更多内容
随时随地看视频慕课网APP