# Diffrence

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

1. ### VijayGuest

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

Vijay, May 29, 2006

2. ### VijayGuest

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. ### VijayGuest

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
4. ### =?ISO-8859-1?Q?Erik_Wikstr=F6m?=Guest

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
5. ### osmiumGuest

"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
6. ### TomásGuest

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
7. ### W MarshGuest

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
8. ### Chris HillsGuest

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
9. ### Keith ThompsonGuest

"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