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 is the benefit of using #define to declare a constant?
Is it better to use malloc() or calloc()?
Write a program for finding factorial of a number.
What is array of structure in c?
What is the most efficient way to store flag values?
while initialization of two dimensional arrays we can initialize like a[][2] but why not a[2][] is there any reason behind this?
Who invented bcpl language?
Why do we need arrays in c?
what is const volatile?
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.
34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?
Can you tell me how to check whether a linked list is circular?