繁体   English   中英

typedef struct和struct之间的区别?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM