Thread: User defined structure

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    6

    User defined structure

    I wrote a code that would create a user-defined structure named Flight with flightNumber and flightMiles members

    Code:
    struct Flight
    {
    int flightNumber; 
    int flightMiles;
    };
    Will someone please correct me if I am wrong

    Thanks


    Jamina

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    The code looks right. But, do you have a problem with it? Otherwise the best way to test it is making your own program that uses it.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    1,619

    Re: User defined structure

    Yes, the code you posted defines (not creates) a struct named Flight with those members. Do note that this does NOT create any of these structures, it only tells the compiler how that structure is made. Until you create an instance of the structure, you can't do anything useful.

  4. #4
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    Yeah, remember to create an instance of the struct by doing:
    Code:
    Flight instance_of_flight;
    instance_of_flight.flightNumber=635;
    instance_of_flight.flightMiles=22;
    but of course use a better name for yours

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sum of User Defined Matrix Powers
    By QuaX in forum C Programming
    Replies: 1
    Last Post: 04-19-2009, 11:33 PM
  2. Style Points
    By jason_m in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:15 AM
  3. Stl lists and user defined types
    By figa in forum C++ Programming
    Replies: 8
    Last Post: 03-28-2005, 12:09 PM
  4. user defined path for FILENAME
    By drdigimon in forum C Programming
    Replies: 5
    Last Post: 10-12-2003, 06:04 PM
  5. Replies: 7
    Last Post: 04-13-2003, 10:53 PM