223k views
5 votes
How to use union in the real world?​

User Iamdeit
by
8.6k points

1 Answer

4 votes

Answer:

To overcome such type of real world problems we use union. Unlike structures union occupies single memory location to store all its members. So, unions are helpful when you want to store value in single member from a set of members. Size of union is defined according to size of largest member data type.

Explanation:

In union, all members share the same memory location. For example in the following C program, both x and y share the same location. If we change x, we can see the changes being reflected in y. #include <stdio.h> // Declaration of union is same as structures.

User Joshua Kravitz
by
7.8k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories