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

asked
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.

answered
User Joshua Kravitz
by
7.8k points

No related questions found

Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.