What is the importance of union in c program?

1 answer

Answer

1215269

2026-08-07 18:16

+ Follow

Importance of union in 'C':unions are the concept borrowed from structures in structures we allow different datatypes in which each datatype is allocated a separate memory location .But in unions same as structures we use different data types but all the datatypes will be allocated to a single memory location and only one datatype with maximum size will be used for allocation of all the data types used in a union program.Sample code for union is as follows:union item

{

int m;

float c;

char x;

}code;

In the above program we used three kinds of datatypes here integer size is 4 so the other data types will be shared in the same location of size 4.then the memory will not be wasted and all the memory will be utilized perfectly.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.