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 |
What does extern mean in a function declaration?
Write a program for deleting duplicate elements in an array
Write a code to determine the total number of stops an elevator would take to serve N number of people.
What is wrong with this code?
What will be the outcome of the following conditional statement if the value of variable s is 10?
How can I read a binary data file properly?
how many keywords are available in 'c' language a) 32 b) 34 c) 45 d) 48
c program to subtract between two numbers without using '-' sign and subtract function.
Write a program to display the no of bit difference between any 2 given numbers eg: Num1 will 12->1100 Num2 will 7->0111 the difference in bits are 2.
What is difference between the following 2 lines…. int temp = (int)(0x00); int temp = (0x00int);
What does c in a circle mean?
write a program to print the one dimensional array.