#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    23
    Rep Power
    0

    Question about structures


    Quick question,

    Defining a struct(ture) should be done before or after the main function? Because I've watched a tutorial in which the tutor said it's done before the main function and I've found several examples in which it was after.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    The only rule is that it should be declared before first use.

    Code:
    struct visibleToAll {
      int a;
    };
    
    int main ( ) {
      struct visibleToMainOnly {
        int a;
      };
    }
    
    struct visibleToAnythingFollowingButNotMain {
      int a;
    };

    Comments on this post

    • Cantafford agrees : like
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    23
    Rep Power
    0
    great thanks!

IMN logo majestic logo threadwatch logo seochat tools logo