Hari Krishnan Hari Krishnan - 2 months ago 11
C Question

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

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?

Answer

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;