I want to know the actual use of struct tag_name in C programming. Without using the tag_name also i was getting output as with use of tag_name. I want the exact reason behind t
If you use the tag, you can create more variables of type struct st1
(or types derived from that (e.g., struct st1*
)) later:
struct st1 z, *zp;
while after:
struct { int x; char c;}x={100,'a'},y={70,'e'};
you can never create variables of this type ever again.
While you can do:
struct { int x; char c;} z = {80, 'f'};
//same layout and member names
it will have a type that's different from that of x's and y's as far as aliasing and type checking is concerned.
The tag allows you to reuse the type.
(Typedefing an anomyous struct
typedef struct { int x; char c;} st1;
st1 x,y,z;
is another way to reuse the type.)