Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 317
User Avatar asked Dec 30 '25 13:12

User


2 Answers

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;
like image 194
Vlad from Moscow Avatar answered Jan 01 '26 05:01

Vlad from Moscow


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;
like image 42
Michał Szydłowski Avatar answered Jan 01 '26 03:01

Michał Szydłowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!