Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it optional to use struct keyword before declaring a structure object?

Tags:

c

struct

To declare a class object we need the format

classname objectname;

Is it the sameway to declare a structure object?

like

structname objectname;

I found here a structure object declared as

struct Books Book1;

where Books is the structure name and Book1 is its object name. So is there any need of usinge the keyword struct before declaring a structure object?

like image 449
Hari Krishnan Avatar asked Oct 03 '16 19:10

Hari Krishnan


1 Answers

You have to typedef them to make objects without struct keyword

example:

typedef struct Books {
     char Title[40];
     char Auth[50];
     char Subj[100];
     int Book_Id;
} Book;

Then you can define an object without the struct keyword like:

Book thisBook;
like image 192
Sajad Avatar answered Sep 27 '22 22:09

Sajad