Union in C language Reviewed by Momizat on . A union allow the overlap of more than one variable.the same memory area.General each and every variable.It's store in a separate location and each variable hav A union allow the overlap of more than one variable.the same memory area.General each and every variable.It's store in a separate location and each variable hav Rating: 0

Union in C language

A union allow the overlap of more than one variable.the same memory area.General each and every variable.It’s store in a separate location and each variable have there own address in the memory.often it is found that the variable used in a program appear only in small portion of the source code but In case of union many variable have the same address.so, it occupies less memory and structure occupies more memory.

It terms of declaration and syntax the union is similar with the structure.the method used to declared structure is adopted to a union.A union datatypes is they just like a structure datatype except that it allows to define variable.which share storage place and union is declare with the keyword union.The compiler will allocate sufficient storage to accommodate the largest element in the union.Unlike structure members of a unions variable occupies is the same location in the memory the updating of one member will over writer the other.

syntax:-

union
{
:::::::::::::
members;
:::::::::::::
}

Different between of structure and union

Union			Structure
5 10 2			5 10 2
x  y z-input	        x  y z----input
|  | |			|  | |		
2--output		5 10  2---output
1009--address   	1009 1010 1011---address	

Leave a Comment

© 2014 Powered By