EmbLogic's Blog

how union differ from the structure!!!

#include<stdio.h>

union abc
{
char a;
int b;
int c;

}z;
int main()
{
printf(“size of union %d\n”,sizeof(union abc));//the size of the union is the maximum size of the data type.
z.a=4;
printf(“the value for a is %d\n”,z.a);
z.b=5;
printf(“***********************after assign the value again**********************\n”);
printf(“the value for b is %d\n”,z.b);//as their is only 1 block of memory is allocated so the previous value will be overwrite.
printf(“the value for a is %d\n”,z.a);
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>