which one is better structure or union?(other than the
space occupied )
Answers were Sorted based on User's Feedback
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 |
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 |
Where local variables are stored in c?
What is the time and space complexities of merge sort and when is it preferred over quick sort?
What is auto keyword in c?
What's wrong with the call "fopen ("c:\newdir\file.dat", "r")"?
Can you assign a different address to an array tag?
WHAT IS HEADER?
Explain what is the best way to comment out a section of code that contains comments?
How can I allocate arrays or structures bigger than 64K?
what do structure language means?
What is pointers in c with example?
What is %d called in c?
How can I read and write comma-delimited text?