which one is better structure or union?(other than the
space occupied )

Answers were Sorted based on User's Feedback



which one is better structure or union?(other than the space occupied )..

Answer / shrikant auti

strucure is always better than union.
there are to reasons
1.
union occupies incorrect memory.
e.g.
if the lower memory space data is preceeded by higher one.
Then memory should be alloted is addition of these two, but
the memory will be alloted will be any one out of higher
and lower there is no way to assure what memory would be
occupied.

2.
the data given in union is not necessarily be(maybe/may not
be) extreacted properly.
but in structure correct amount of memory space will be
occupied and extracting element is easy.

Is This Answer Correct ?    13 Yes 2 No

which one is better structure or union?(other than the space occupied )..

Answer / nishit jain

There is no question of which one is better. Both are there
for different functionality. Structures find more usage in
day-today programming, while unions are used less often.
There are examples where structure may not solve the purpose
but unions will work without much effort. Example :
packing-unpacking of data can be done using unions easily.

Is This Answer Correct ?    7 Yes 2 No

Post New Answer

More C Interview Questions

In c language can we compile a program without main() function?

0 Answers  


what is a c-language.what is do.

4 Answers   HCL,


what is the difference between call by value and call by reference?

5 Answers   Genpact, Global Logic, Infosys,


how can i get the string which is having two spaces at the end.suppose the string is "Hello World ".Now at the end i have two spaces.i need to print with that spaces .

1 Answers  


Is c language still used?

0 Answers  






Suggesting that there can be 62 seconds in a minute?

0 Answers  


4) Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

5 Answers  


which operator having lowest precedence?? a.)+ b.)++ c.)= d.)%

4 Answers  


What is %d used for?

0 Answers  


what is the difference between. system call and library function?

2 Answers   CDAC, Satyam,


Who developed c language?

0 Answers  


Fifty minutes ago if it was four times as many mints past 3 o clock. how many minutes is it to six o'clock n how....?????

3 Answers   TCS,


Categories