+ 1

Does the value of y change to 4 everywhere in the code after cout<<--y?

#include <iostream> using namespace std; int main() { int x=4; int y=++x; x=y+x; cout <<--y; return 0; }

14th Jul 2018, 9:43 AM
Yelyzaveta Al-Dara
2 Answers
+ 1
Yes, because you use a pre decrement operator and the priority of this operator is highest.. so y will become 4 before printing it's value.
15th Jul 2018, 7:44 PM
Pushpajit-Biswas
Pushpajit-Biswas - avatar
+ 4
Since you use a pre-decrement operator on 'y' then value of 'y' is decreased to 4 just before it is printed. And after the 'cout --y;' the 'y' value became 4, so there ... Hth, cmiiw
14th Jul 2018, 9:50 AM
Ipang