0

Code of c

Can anyone tell me answer of this code : union Values { int first; int second; }; int main (){ union Values v; v.first=0; v second=4+v.first; v.first=v.second+4; printf("%d\n",v.second); return 0; } Code is correct but my answer was 4 which was wrong so please tell me correct answer.

15th Jul 2020, 1:26 PM
Prasad Bankar
Prasad Bankar - avatar
3 Answers
+ 2
Prasad Bankar answer is 8
15th Jul 2020, 1:35 PM
Varun N
Varun N - avatar
+ 2
Prasad Bankar at the end union variable stores 8. Even though you declared two elements inside the union ,only one block of memory will be allocated (which has higher priority)
15th Jul 2020, 3:03 PM
uday kiran
uday kiran - avatar
0
Yes but I didn't understand why v.second is 8
15th Jul 2020, 4:42 PM
Prasad Bankar
Prasad Bankar - avatar