Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Diffrence (http://www.velocityreviews.com/forums/t442924-diffrence.html)

Vijay 05-29-2006 11:23 AM

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


Vijay 05-29-2006 11:26 AM

Re: Diffrence
 
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 05-29-2006 11:27 AM

Re: Diffrence
 
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.


=?ISO-8859-1?Q?Erik_Wikstr=F6m?= 05-29-2006 01:06 PM

Re: Diffrence
 
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

osmium 05-29-2006 01:31 PM

Re: Diffrence
 
"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?



Tomás 05-29-2006 03:14 PM

Re: Diffrence
 
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

W Marsh 05-29-2006 04:54 PM

Re: Diffrence
 
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...

Chris Hills 05-29-2006 05:41 PM

Re: Diffrence
 
In article <1148901810.564484.274870@u72g2000cwu.googlegroups .com>,
Vijay <jais_myvijay@yahoo.co.in> 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 /\/\/\/\/
/\/\/ chris@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/




Keith Thompson 05-29-2006 06:55 PM

Re: Diffrence
 
"Vijay" <jais_myvijay@yahoo.co.in> 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) kst-u@mib.org <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.


All times are GMT. The time now is 08:18 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.