![](/img/trans.png)
[英]What's the difference between `typedef struct X { }` and `typedef struct { } X`?
[英]Difference between typedef struct and struct?
我知道他们之间的基本区别只是在以下特殊情况下有疑问:
struct books{
int id;
char* title;
}book;
book.id=9; // this is valid;
但是在typedef
情况下:
typedef struct books{
int id;
char*title;
}book;
book.id=9; //it is not valid we have to do like book b1; then b1.id=9 is valid
你能告诉我的是这里发生了什么?
在第一种情况下,您将创建一个名为book
struct books
类型的对象。
在第二部分中,您将为struct books
定义一个别名book
。 因此, book
不是对象而是类型名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.