Union frequently asked interview questions in C programming Language.

Q6.How to Calculate the size of Union in C?
The size of union in C language is the size of largest member in union.Let us say if union contain an integer array of 10 integers then the size of union will be the size of the largest member, which is approximetly equal to 40 bytes ( the 10 elements * 4 bytes each)

Q7.What are uses of Union in C?
The main fundamental or primary use of union is allowing access to common memory location by different data types.
e.g Hardware output/input access,word sharing and bitfield or type punning.

Q8.What are Advantages of Union in C.
There are several advantages of union in c programming Language.
Improved code readability:
  With the help of union code becomes more redable by allowing different types of data to be grouped together and accessed in organized and logical way.
Memory efficiency:
  A union in C uses the same memory location for all of its members, This is a more memory-efficient way to store data members as compared to using scalar or separate variables for each type of data.
Flexibility:
  Union in C programming language provide flexibility. As union is used to store different data types members, and only one member is able to use memory at a given point of time .
Optimization:
  Unions in c is useful for space optimization,Because it only uses the specific amount of memory required for the largest member.
Q8.What is the syntax of union in C?
union union_name
 {
  data type member1;
  data type member2;
  data type member3;
   }t;
t.member;  //to access members of union t t. use the member access operator ( . ) dot to access members of a union in C. The (.) dot is used between the union variable name and the union member that we want to access.
Syntax for accessing any union member is same as that of accessing structure members.


Previous Topic:-->> Union examples in C. || Next topic:-->>What is pointer in C