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

main() { int arr[5]={23,67}; printf("%d%d%d",arr[2],arr[3],arr[4]); }

9 Answers   TCS,


Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates

3 Answers  


Explain two-dimensional array.

0 Answers  


void main(int argc,char *argv[],char *env[]) { int i; for(i=1;i<argc;i++) printf("%s",env[i]); }

3 Answers  


what are two categories of clint-server application development ?

1 Answers  






main() { int i=5; printf("%d",++i + i); } output is 10 ------------------------ main() { int i=5; printf("%d",i++ + i); }output is 12 why it is so? give appropiate reason....

2 Answers  


Explain what is the benefit of using an enum rather than a #define constant?

0 Answers  


Explain how can I read and write comma-delimited text?

0 Answers  


Can 'this' pointer by used in the constructor?

0 Answers  


simple program of graphics and their output display

0 Answers   Elysium,


Can we assign integer value to char in c?

0 Answers  


What is c programing language?

0 Answers  


Categories