Search code examples
cstructdeclarationdefinition

What is the word after a struct?


struct Books
{
   char  title[50];
   char  author[50];
   char  subject[100];
   int   book_id;
} book;  

What exactly is "book" at the end?


Solution

  • It is a declaration of an instance of a structure of type struct Books with name book.

    It is equivalent to

    struct Books
    {
       char  title[50];
       char  author[50];
       char  subject[100];
       int   book_id;
    };
    
    struct Books book;
    

    Take into account that in general declarations look like (simplified form)

    type-sepcifier identifier;
    

    where identifier is some declarator. For example

    int x;
    

    And a structure definition also belongs to type specifiers.

    So you may write for example

    struct A { int x; } s;