Hari Krishnan Hari Krishnan - 1 year ago 63
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?


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
before declaring a structure object?

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download