what are the advantages & disadvantages of unions?

Answers were Sorted based on User's Feedback



what are the advantages & disadvantages of unions?..

Answer / vishnu nayak

Union occupy same memory area for different members in a
union.
Same are is allocated for different data types of the
members of union
eg:
union
{
int a;
char c;
float f;
}temp;
Size of Float will be size of union.
same memory is used for char and int as well.
Advantages: Memory consumption is less.
Disadvanteges: if one of the member variable is updated the
it will be reflected in the remaining 2 variables.

Is This Answer Correct ?    62 Yes 18 No

what are the advantages & disadvantages of unions?..

Answer / vadivelt

Main disadvantage is, all the union member variables cannot
be initialised or used with different values at a time.

Is This Answer Correct ?    45 Yes 14 No

Post New Answer

More C Interview Questions

When we use void main and int main?

0 Answers  


struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer

0 Answers  


To what value do nonglobal variables default? 1) auto 2) register 3) static

4 Answers  


How do you sort filenames in a directory?

0 Answers  


Write a program to find minimum between three no.s whithout using comparison operator.

4 Answers   IBM,






What is data structure in c and its types?

0 Answers  


process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,

0 Answers   InterGraph,


how many times of error occur in C

11 Answers  


when user give a number it multiply with 9 without useing '+' and '*' oprator

4 Answers  


Can you please explain the difference between strcpy() and memcpy() function?

0 Answers  


How can you increase the size of a dynamically allocated array?

0 Answers   TISL,


Write a program that takes three variables(a,b,c) in as separate parameters and rotates the values stored so that value a goes to b,b,to c and c to a

7 Answers  


Categories