Why do we leave some structure variables out of the curly brackets?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
8
down vote

favorite












I'm trying to understand struct in C. I couldn't get the idea about this definition below. Why do we leave aCard, deck[ ] and *cardPtr out? What is the difference between including them in and leaving them out?



 struct card 
char *face;
char *suit;
aCard, deck[52], *cardPtr;









share|improve this question























  • Think of it this way: the deck, per example is not the property of a card. A card can exist on its own without a deck. So the deck is not part of card.
    – Blaze
    23 mins ago














up vote
8
down vote

favorite












I'm trying to understand struct in C. I couldn't get the idea about this definition below. Why do we leave aCard, deck[ ] and *cardPtr out? What is the difference between including them in and leaving them out?



 struct card 
char *face;
char *suit;
aCard, deck[52], *cardPtr;









share|improve this question























  • Think of it this way: the deck, per example is not the property of a card. A card can exist on its own without a deck. So the deck is not part of card.
    – Blaze
    23 mins ago












up vote
8
down vote

favorite









up vote
8
down vote

favorite











I'm trying to understand struct in C. I couldn't get the idea about this definition below. Why do we leave aCard, deck[ ] and *cardPtr out? What is the difference between including them in and leaving them out?



 struct card 
char *face;
char *suit;
aCard, deck[52], *cardPtr;









share|improve this question















I'm trying to understand struct in C. I couldn't get the idea about this definition below. Why do we leave aCard, deck[ ] and *cardPtr out? What is the difference between including them in and leaving them out?



 struct card 
char *face;
char *suit;
aCard, deck[52], *cardPtr;






c






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 16 mins ago









Micha Wiedenmann

9,0081061100




9,0081061100










asked 28 mins ago









Belverus

514




514











  • Think of it this way: the deck, per example is not the property of a card. A card can exist on its own without a deck. So the deck is not part of card.
    – Blaze
    23 mins ago
















  • Think of it this way: the deck, per example is not the property of a card. A card can exist on its own without a deck. So the deck is not part of card.
    – Blaze
    23 mins ago















Think of it this way: the deck, per example is not the property of a card. A card can exist on its own without a deck. So the deck is not part of card.
– Blaze
23 mins ago




Think of it this way: the deck, per example is not the property of a card. A card can exist on its own without a deck. So the deck is not part of card.
– Blaze
23 mins ago












5 Answers
5






active

oldest

votes

















up vote
8
down vote



accepted










You are mixing things up. A struct card has the fields face and suit. But there are three variables using the struct card type, namely aCard, deck, cardPtr.



Alternatively one could have written:



typdef struct 
char *face;
char *suit;
Card;

Card aCard, deck[52], *cardPtr;
// or even
Card aCard;
Card deck[52];
Card *cardPtr;


For the typedef have a look at: Why should we typedef a struct so often in C? (It goes into typedef struct ... Foo; vs struct Foo ... debate).






share|improve this answer





























    up vote
    4
    down vote













    Your piece of code could be written like this which makes it clearer:



    struct card // define the struct card
    char *face;
    char *suit;
    ;

    struct card aCard; // declare a variable "aCard" of type "struct card "
    struct card deck[52] // declare an array of 52 variables of type "struct card"
    struct card *cardPtr; // declare a variable "cardPtr" of type "pointer to struct card"





    share|improve this answer



























      up vote
      2
      down vote













      a



      struct card 
      char *face;
      char *suit;



      is just like int, but it is user defined, and



      aCard, deck[52], *cardPtr;


      are variable names, e.g.



      int aCard, deck[41], *cardPtr;





      share|improve this answer



























        up vote
        1
        down vote













        aCard and the rest you have mentioned are variables of type struct card and each of these variables contain char *face and char *suit. So how can some variable can contain itself i.e. aCard being inside the struct node.






        share|improve this answer



























          up vote
          0
          down vote













          You have declared three variables. aCard is of type struct card, deck is of type struct card[52] and cardPtr is of type struct card *






          share|improve this answer




















            Your Answer





            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52851455%2fwhy-do-we-leave-some-structure-variables-out-of-the-curly-brackets%23new-answer', 'question_page');

            );

            Post as a guest






























            5 Answers
            5






            active

            oldest

            votes








            5 Answers
            5






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            8
            down vote



            accepted










            You are mixing things up. A struct card has the fields face and suit. But there are three variables using the struct card type, namely aCard, deck, cardPtr.



            Alternatively one could have written:



            typdef struct 
            char *face;
            char *suit;
            Card;

            Card aCard, deck[52], *cardPtr;
            // or even
            Card aCard;
            Card deck[52];
            Card *cardPtr;


            For the typedef have a look at: Why should we typedef a struct so often in C? (It goes into typedef struct ... Foo; vs struct Foo ... debate).






            share|improve this answer


























              up vote
              8
              down vote



              accepted










              You are mixing things up. A struct card has the fields face and suit. But there are three variables using the struct card type, namely aCard, deck, cardPtr.



              Alternatively one could have written:



              typdef struct 
              char *face;
              char *suit;
              Card;

              Card aCard, deck[52], *cardPtr;
              // or even
              Card aCard;
              Card deck[52];
              Card *cardPtr;


              For the typedef have a look at: Why should we typedef a struct so often in C? (It goes into typedef struct ... Foo; vs struct Foo ... debate).






              share|improve this answer
























                up vote
                8
                down vote



                accepted







                up vote
                8
                down vote



                accepted






                You are mixing things up. A struct card has the fields face and suit. But there are three variables using the struct card type, namely aCard, deck, cardPtr.



                Alternatively one could have written:



                typdef struct 
                char *face;
                char *suit;
                Card;

                Card aCard, deck[52], *cardPtr;
                // or even
                Card aCard;
                Card deck[52];
                Card *cardPtr;


                For the typedef have a look at: Why should we typedef a struct so often in C? (It goes into typedef struct ... Foo; vs struct Foo ... debate).






                share|improve this answer














                You are mixing things up. A struct card has the fields face and suit. But there are three variables using the struct card type, namely aCard, deck, cardPtr.



                Alternatively one could have written:



                typdef struct 
                char *face;
                char *suit;
                Card;

                Card aCard, deck[52], *cardPtr;
                // or even
                Card aCard;
                Card deck[52];
                Card *cardPtr;


                For the typedef have a look at: Why should we typedef a struct so often in C? (It goes into typedef struct ... Foo; vs struct Foo ... debate).







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 18 mins ago

























                answered 26 mins ago









                Micha Wiedenmann

                9,0081061100




                9,0081061100






















                    up vote
                    4
                    down vote













                    Your piece of code could be written like this which makes it clearer:



                    struct card // define the struct card
                    char *face;
                    char *suit;
                    ;

                    struct card aCard; // declare a variable "aCard" of type "struct card "
                    struct card deck[52] // declare an array of 52 variables of type "struct card"
                    struct card *cardPtr; // declare a variable "cardPtr" of type "pointer to struct card"





                    share|improve this answer
























                      up vote
                      4
                      down vote













                      Your piece of code could be written like this which makes it clearer:



                      struct card // define the struct card
                      char *face;
                      char *suit;
                      ;

                      struct card aCard; // declare a variable "aCard" of type "struct card "
                      struct card deck[52] // declare an array of 52 variables of type "struct card"
                      struct card *cardPtr; // declare a variable "cardPtr" of type "pointer to struct card"





                      share|improve this answer






















                        up vote
                        4
                        down vote










                        up vote
                        4
                        down vote









                        Your piece of code could be written like this which makes it clearer:



                        struct card // define the struct card
                        char *face;
                        char *suit;
                        ;

                        struct card aCard; // declare a variable "aCard" of type "struct card "
                        struct card deck[52] // declare an array of 52 variables of type "struct card"
                        struct card *cardPtr; // declare a variable "cardPtr" of type "pointer to struct card"





                        share|improve this answer












                        Your piece of code could be written like this which makes it clearer:



                        struct card // define the struct card
                        char *face;
                        char *suit;
                        ;

                        struct card aCard; // declare a variable "aCard" of type "struct card "
                        struct card deck[52] // declare an array of 52 variables of type "struct card"
                        struct card *cardPtr; // declare a variable "cardPtr" of type "pointer to struct card"






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 21 mins ago









                        Jabberwocky

                        24.9k93666




                        24.9k93666




















                            up vote
                            2
                            down vote













                            a



                            struct card 
                            char *face;
                            char *suit;



                            is just like int, but it is user defined, and



                            aCard, deck[52], *cardPtr;


                            are variable names, e.g.



                            int aCard, deck[41], *cardPtr;





                            share|improve this answer
























                              up vote
                              2
                              down vote













                              a



                              struct card 
                              char *face;
                              char *suit;



                              is just like int, but it is user defined, and



                              aCard, deck[52], *cardPtr;


                              are variable names, e.g.



                              int aCard, deck[41], *cardPtr;





                              share|improve this answer






















                                up vote
                                2
                                down vote










                                up vote
                                2
                                down vote









                                a



                                struct card 
                                char *face;
                                char *suit;



                                is just like int, but it is user defined, and



                                aCard, deck[52], *cardPtr;


                                are variable names, e.g.



                                int aCard, deck[41], *cardPtr;





                                share|improve this answer












                                a



                                struct card 
                                char *face;
                                char *suit;



                                is just like int, but it is user defined, and



                                aCard, deck[52], *cardPtr;


                                are variable names, e.g.



                                int aCard, deck[41], *cardPtr;






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered 21 mins ago









                                BladeMight

                                7861021




                                7861021




















                                    up vote
                                    1
                                    down vote













                                    aCard and the rest you have mentioned are variables of type struct card and each of these variables contain char *face and char *suit. So how can some variable can contain itself i.e. aCard being inside the struct node.






                                    share|improve this answer
























                                      up vote
                                      1
                                      down vote













                                      aCard and the rest you have mentioned are variables of type struct card and each of these variables contain char *face and char *suit. So how can some variable can contain itself i.e. aCard being inside the struct node.






                                      share|improve this answer






















                                        up vote
                                        1
                                        down vote










                                        up vote
                                        1
                                        down vote









                                        aCard and the rest you have mentioned are variables of type struct card and each of these variables contain char *face and char *suit. So how can some variable can contain itself i.e. aCard being inside the struct node.






                                        share|improve this answer












                                        aCard and the rest you have mentioned are variables of type struct card and each of these variables contain char *face and char *suit. So how can some variable can contain itself i.e. aCard being inside the struct node.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered 24 mins ago









                                        Observer

                                        956113




                                        956113




















                                            up vote
                                            0
                                            down vote













                                            You have declared three variables. aCard is of type struct card, deck is of type struct card[52] and cardPtr is of type struct card *






                                            share|improve this answer
























                                              up vote
                                              0
                                              down vote













                                              You have declared three variables. aCard is of type struct card, deck is of type struct card[52] and cardPtr is of type struct card *






                                              share|improve this answer






















                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                You have declared three variables. aCard is of type struct card, deck is of type struct card[52] and cardPtr is of type struct card *






                                                share|improve this answer












                                                You have declared three variables. aCard is of type struct card, deck is of type struct card[52] and cardPtr is of type struct card *







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered 22 mins ago









                                                Broman

                                                5,64092241




                                                5,64092241



























                                                     

                                                    draft saved


                                                    draft discarded















































                                                     


                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52851455%2fwhy-do-we-leave-some-structure-variables-out-of-the-curly-brackets%23new-answer', 'question_page');

                                                    );

                                                    Post as a guest













































































                                                    Comments

                                                    Popular posts from this blog

                                                    What does second last employer means? [closed]

                                                    List of Gilmore Girls characters

                                                    One-line joke