+ 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; }
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.
+ 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