Diffrence

Discussion in 'C Programming' started by Vijay, May 29, 2006.

  1. Vijay

    Vijay Guest

    Can you tell me what is the diffrence between structure and union.
     
    Vijay, May 29, 2006
    #1
    1. Advertising

  2. Vijay

    Vijay Guest

    structure alocates diffrent locations for all it memberrs but the union
    creates only a single largest location to store only one member of
    union at a time.
     
    Vijay, May 29, 2006
    #2
    1. Advertising

  3. Vijay

    Vijay Guest

    structure alocates diffrent locations for all it memberrs but the union
    creates only a single largest location to store only one member of
    union at a time.
     
    Vijay, May 29, 2006
    #3
  4. On 2006-05-29 13:23, Vijay wrote:
    > Can you tell me what is the diffrence between structure and union.


    In a struct the members are placed on separate memory locations so in
    the following example one and two does not occupy the same memory.

    struct s { int i1; int i2; };

    In memory it could look like this

    |--------|--------|
    <--i1--> <--i2-->

    With a union on the other hand the members occupy the same memory
    location like this:

    union u { int i1; int i2; };

    |--------|--------|
    <--i1-->
    <--i2-->

    That means if you change the value of i1 you also change the value of
    i2, this makes unions dangerous. Add to this the fact that the alignment
    of the members in unspecified and may differ between architectures and
    you quickly run into portability-issues. In short, don't use unions if
    you are not 100% sure of what you are doing.

    Erik Wikström
    --
    "I have always wished for my computer to be as easy to use as my
    telephone; my wish has come true because I can no longer figure
    out how to use my telephone" -- Bjarne Stroustrup
     
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, May 29, 2006
    #4
  5. Vijay

    osmium Guest

    "Vijay" writes:

    > structure alocates diffrent locations for all it memberrs but the union
    > creates only a single largest location to store only one member of
    > union at a time.


    Is this some new kind of indecipherable game? Where the contestant asks a
    question of his choosing and then answers it?
     
    osmium, May 29, 2006
    #5
  6. Vijay

    Tomás Guest

    Vijay posted:

    > Can you tell me what is the diffrence between structure and union.



    "structure" contains nine letters, three of which are vowels, six of which
    are consonants.

    "union" contains five ltters, three of which are vowels, two of which are
    consonants.


    -Tomás
     
    Tomás, May 29, 2006
    #6
  7. Vijay

    W Marsh Guest

    On Mon, 29 May 2006 15:14:56 GMT, "Tomás" <No.Email@Address> wrote:

    >"structure" contains nine letters, three of which are vowels, six of which
    >are consonants.
    >
    >"union" contains five ltters, three of which are vowels, two of which are
    >consonants.


    "letters" contains...
     
    W Marsh, May 29, 2006
    #7
  8. Vijay

    Chris Hills Guest

    In article <>,
    Vijay <> writes
    >Can you tell me what is the diffrence between structure and union.
    >


    All structures MUST belong to a Union.

    It is the Structures Union Co-operative Kabul. This is why all
    structures SUCK. Structures not in a union are "un-named" or master-
    less structures.


    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, May 29, 2006
    #8
  9. "Vijay" <> writes:
    > Can you tell me what is the diffrence between structure and union.


    This must be a trick question. There is no "-" operator defined for
    either structures or unions.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, May 29, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mohammed rafi
    Replies:
    3
    Views:
    14,511
    Charles Bailey
    May 7, 2004
  2. mohammed rafi
    Replies:
    1
    Views:
    1,345
    ben cohen
    May 6, 2004
  3. ITpro
    Replies:
    2
    Views:
    2,622
    David N. Welton
    Oct 29, 2005
  4. vj
    Replies:
    17
    Views:
    23,697
    jessie143143
    Oct 21, 2012
  5. Luai

    Diffrence between ++i and i++

    Luai, Apr 12, 2004, in forum: C Programming
    Replies:
    12
    Views:
    11,652
    Mabden
    May 7, 2004
Loading...

Share This Page