Decode School

Decode School - The School for Problem Solvers

Welcome to my blog. Subscribe and get my latest blog post in your inbox.

Example to Illustrate Union

Illustrate how members of union are sharing same memory.

Program or Solution

					    
							
union area
{
   int x, y;
};
 
int main()
{
    union area a;
 
    a.x = 2; 
    printf ("After making x = 2:\n x = %d, y = %d\n\n",
             a.x, a.y);
 
    t.y = 10;  
    printf ("After making Y = 10:\n x = %d, y = %d\n\n",
             a.x, a.y);
    return 0;
}

					    
					

Program Explanation

because both x any shares same memory changes in on variable affects the another.