I was looking at this struct tutorial.

https://www.tutorialspoint.com/cprogramming/c_structures.htm

It mentions "The structure tag is optional". How would you refer to your struct if there is no structure tag?

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

//something like this? 
struct random_name;

Recommended Answers

All 2 Replies

The structure tag is optional because there are instances where you want a one-off structure;

struct {
    int foo;
    char bar[4];
} my_unique_data_structure;  // only struct of this form

The tag is for when you want to name the structure template or type.

struct quux {
    int baz, bang, zing;
};

struct quux whoopie;

You can also declare instances of a named structure following the structure definition, for cases where you know ahead of time that you need at least one structure of that type:

struct quux {
    int baz, bang, zing;
} whoopie;

// later ...
struct quux flarp;

I hope this makes it a bit clearer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.