Code of c | Sololearn: Learn to code for FREE!


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.

7/15/2020 1:26:19 PM

Prasad Bankar

3 Answers

New Answer


Prasad Bankar answer is 8


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)


Yes but I didn't understand why v.second is 8