I am trying to learn memory allocation in c for union and having a problem trying to do so
#include <stdio.h>
union abc
{
int a;
char name[5];
};
int main()
{
union abc hh;
printf("Enter two values\n");
scanf("%d%s",&hh.a,&hh.name);
printf("Values are\n");
printf("%d\n%s",hh.a,hh.name);
return 0;
}
As seen in the above code i am trying to store two values in a union.But however the result i am getting after enter values as '23' and 'p' is
Enter two values
23
p
Values are
112
p
Can someone help me regarding above code