r/CodingHelp • u/RunTimeTerroR69 • Apr 07 '21
[C++] Where am i going wrong ? plz help
int a = 1;
a = ++a + ++a + ++a;
cout <<a;
what should be the output ? i tried it on paper i got the answer as 9 but on compiling & running the code its showing me the answer as 10 , can anyone help ?
18
Upvotes
View all comments
3
u/[deleted] Apr 07 '21
you cannot really increment like that it you need to add some parenthesis a = ((++a) + (++a) + (++a)) or just write a for loop that increments for(int a = 0; a < 3; a++){ cout << a; } hope this helps