What is the use of Struct Tag name in C programming?

前端 未结 3 631
孤独总比滥情好
孤独总比滥情好 2021-02-09 15:39

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

3条回答
  •  孤独总比滥情好
    2021-02-09 16:30

    In the first case :

    struct st1 { 
        int x; 
        char c;
    } x = {100, 'a'}, y = {70, 'e'};
    

    you declare a type with name struct st1, and you also create two objects, of this type, x and y. So you can create objects of this type whenever you want, like this :

    struct st1 obj1;
    

    However in the second case :

    struct { 
        int x; 
        char c;
    } x = {100, 'a'}, y = {70, 'e'};
    

    you create a struct and two objects, x and y, but you cannot access this struct again. This means that you cannot create any new objects of this type.

提交回复
热议问题