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

Define a structure to store the record of library. The record must consist of at least following fields: Title, Author, Edition, Price, Publisher, and Category. -Define functions authorSearch ( ), TitleSearch ( ) and CategorySearch ( ) to search a book with respect to author, title and category. [There can be more than one book, written by one author, in one category]

2 Answers  


what is the need for main function in c?

5 Answers  


Explain the priority queues?

0 Answers  


how to find the size of the data type like int,float without using the sizeof operator?

13 Answers  


why do we use # in c-language?

1 Answers  






how can i print "hello"

3 Answers  


What is the best way of making my program efficient?

0 Answers  


can we change the default calling convention in c if yes than how.........?

0 Answers   Aptech,


Which header file is essential for using strcmp function?

0 Answers  


Define function ?Explain about arguments?

2 Answers   Geometric Software, Infosys,


What is a macro in c preprocessor?

0 Answers  


what is the use of ~ in c lang?????

3 Answers  


Categories