Thread: C programming

  1. #1
    Registered User jacktibet's Avatar
    Join Date
    Mar 2003
    Posts
    18

    Question C programming

    what is the difference between

    typedef struct {
    type1 id_list1;
    type2 id_list2;
    .....
    }struct_type;


    and

    struct struct_type{
    type1 id_list1;
    type2 id_list2;
    .....
    };

    I am confused.
    please explain it. Thank you

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    23
    If you declare your struct like this:
    Code:
    typedef struct {
    type1 id_list1;
    type2 id_list2;
    .....
    }struct_type;
    you can declare a struct variable like this:
    Code:
    struct_type mytype;
    If you declare you struct like this:
    Code:
    struct struct_type{
    type1 id_list1;
    type2 id_list2;
    .....
    };
    you have to declare a struct variable like this:
    Code:
    struct struct_type mytype;

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    typedef struct {
        type1 id_list1;
        type2 id_list2;
        .....
    }struct_type;
    This defines a new data type called 'struct_type'. You use it like:

    struct_type x;

    This creates an instance of 'struct_type' called 'x'.
    Code:
    struct struct_type{
        type1 id_list1;
        type2 id_list2;
        .....
    };
    This defines a structure with a name. To use it, you use:

    struct struct_type x;

    This creates an instance of a named structure, called 'x'.


    [edit] Curses, foiled again! [/edit]

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed