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 |
write a c program to find biggest of 3 number without relational operator?
What are local static variables? How can you use them?
PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE
Can a variable be both static and volatile in c?
#define f(x) main() { printf("\n%d",f(2+2)); }
what is the output of below pgm? void main() { int i=0; if(i) printf("pass"); else printf("fail"); }
What is c language & why it is used?
what is ans for this scanf(%%d",c);
int n=1; while(1) { switch(n) { case 1:printf("a"); n++; continue; case 2:printf("b"); n++; continue; default : printf("c"); break; } break; }
How can you convert integers to binary or hexadecimal?
How to reverse alternate words in a given line of string For Eg: my name is narasimha output : my eman is ahmisaran
How do I round numbers?