Why is the output 100 100? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Why is the output 100 100?

#include <stdio.h> int main() { union{ int i1; int i2; }myVar={.i2=100}; printf("%d %d",myVar.i1,myVar.i2); return 0; }

26th Jan 2019, 2:48 PM
Zhenis Otarbay
Zhenis Otarbay - avatar
1 Answer
+ 2
Unions store all of their variables in the same place without offsets.
26th Jan 2019, 3:01 PM
Just4f
Just4f - avatar