In this code how output is 65? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

In this code how output is 65?

#include <iostream> using namespace std; int main() { union data { int i; unsigned c; }data; data.i=89; data.c='A'; cout<<data.i; return 0; }

15th Sep 2017, 1:08 PM
SANGMESH PATIL
SANGMESH PATIL - avatar
2 Answers
0
union is memory area, that stores all its members, but it's is size of biggest member. int and unsigned int have same size, so I and c take same memory area and if c changed i changed too.
15th Sep 2017, 6:58 PM
Stephan
Stephan - avatar
0
Try change c to 4 000 000 000 and look at I. It should wonder you. But that value depends on your compiler.
15th Sep 2017, 7:01 PM
Stephan
Stephan - avatar