User
User

Reputation: 24731

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?

Upvotes: 2

Views: 1161

Answers (2)

Vlad from Moscow
Vlad from Moscow

Reputation: 310980

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;

Upvotes: 8

Michał Szydłowski
Michał Szydłowski

Reputation: 3409

It's a variable name, it's a more compact version of:

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

struct Books book;

Upvotes: 2

Related Questions