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 |
Why is c so important?
Multiply an Integer Number by 2 Without Using Multiplication Operator
What are global variables and explain how do you declare them?
What is the concatenation operator?
A text file that contains declarations used by a group of functions,programs,or users a) executable file b) header file c) obj file d) .cfile
Write a program to print the following series 2 5 11 17 23 31 41 47 59 ...
What is variable declaration and definition in c?
#define DCHAR char* typedef char* TCHAR; if using these following variables will be declared like DCHAR ch1, ch2; TCHAR ch3, ch4; then what will be types of ch1, ch2, ch3 and ch4?
What are the application of void data type in c?
Why we use stdio h in c?
Is array a primitive data type in c?
How can I remove the trailing spaces from a string?