Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Diffrence

Reply
Thread Tools

Diffrence

 
 
Vijay
Guest
Posts: n/a
 
      05-29-2006
Can you tell me what is the diffrence between structure and union.

 
Reply With Quote
 
 
 
 
Vijay
Guest
Posts: n/a
 
      05-29-2006
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.

 
Reply With Quote
 
 
 
 
Vijay
Guest
Posts: n/a
 
      05-29-2006
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.

 
Reply With Quote
 
=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      05-29-2006
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
 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      05-29-2006
"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?


 
Reply With Quote
 
Tomás
Guest
Posts: n/a
 
      05-29-2006
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
 
Reply With Quote
 
W Marsh
Guest
Posts: n/a
 
      05-29-2006
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...
 
Reply With Quote
 
Chris Hills
Guest
Posts: n/a
 
      05-29-2006
In article <(E-Mail Removed) .com>,
Vijay <(E-Mail Removed)> 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 /\/\/\/\/
/\/\/ http://www.velocityreviews.com/forums/(E-Mail Removed) www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-29-2006
"Vijay" <(E-Mail Removed)> 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) (E-Mail Removed) <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Diffrence Between Notify & NotifyAll ? vj Java 17 10-21-2012 03:12 PM
Diffrence between application server and web server ITpro Java 2 10-29-2005 11:17 AM
Diffrence between ++i and i++ Luai C Programming 12 05-07-2004 09:26 PM
diffrence between signal, variable and wire, register mohammed rafi VHDL 3 05-07-2004 05:56 PM
diffrence between wire (in verilog) and signal (in vhdl) mohammed rafi VHDL 1 05-06-2004 04:21 PM



Advertisments