Example to Illustrate Union

Illustrate how members of union are sharing same memory.

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#include<stdio.h> int main() { //write your code here }

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.

Comments


Related Programs