[英]Difference between typedef struct and struct?
I know the basic difference between them just have a doubt in particular situation like following: 我知道他们之间的基本区别只是在以下特殊情况下有疑问:
struct books{
int id;
char* title;
}book;
book.id=9; // this is valid;
But in case of typedef
: 但是在
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
What is going on here can u tell me? 你能告诉我的是这里发生了什么?
In your first case, you are creating an object of type struct books
named book
. 在第一种情况下,您将创建一个名为
book
struct books
类型的对象。
In the second, you are defining an alias book
for the type struct books
. 在第二部分中,您将为
struct books
定义一个别名book
。 Thus book
is not an object but a type name. 因此,
book
不是对象而是类型名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.