0

Can someone please explain how is the output of the code 3 ?

int a[]= {3,4}; int x=0; a[x]=++x; cout <<a[0];

19th Apr 2017, 11:29 AM
Aniket Singh
2 Answers
+ 10
It shouldn't be. a[x] -> x is still 0, so the first entry. =++x; -> x is incremented to 1 and is assigned to the first entry. So when a[0] is printed, it should output 1.
19th Apr 2017, 11:37 AM
J.G.
J.G. - avatar
0
but I have​ checked it's 3
19th Apr 2017, 6:24 PM
Aniket Singh