Structure and Union Initialization
#include<stdio.h>
struct first
{
int x, y;
};
union second
{
int x, y;
};
main()
{
struct
first f1 = {1, 2};
printf("\nf1.x = %d \t f1.y = %d",
f1.x, f1.y);
union
second s1;
s1.x = 3;
printf("\ns1.x = %d\t", s1.x);
s1.y = 4;
printf("\ns1.y = %d", s1.y);
union
second s2 = {6, 7};
printf("\ns2.x = %d\t s2.y = %d",
s2.x, s2.y);
union
second s3;
s3.x = 10;
s3.y
= 9;
printf("\ns3.x = %d\t s3.y = %d",
s3.x, s3.y);
}
Output:
f1.x = 1 f1.y =
2
s1.x = 3 s1.y =
4
s2.x = 6 s2.y = 6
s3.x
= 9 s3.y = 9
No comments:
Post a Comment