Here goes the first code:
#include<stdio.h> int main(){ union var{ int a; int b; }; union var v; v.b=10; v.a=5; printf("%d", v.b); return 0; }
This gives 5 as the output.
However, consider this code:
#include<stdio.h> int main(){ union var{ int a; float b; }; union var v; v.b=10.0; v.a=5; printf("%f", v.b); return 0; }
This gives 0.000000 as the output.
Any explanations?
https://stackoverflow.com/questions/65839212/why-is-there-a-contradiction-in-the-output-by-two-programs-written-below-unions January 22, 2021 at 12:14PM
没有评论:
发表评论