+ 1
Why doesn't the value decrease after decreasing it in cout ? Wondering
Ex: #include <iostream> using namespace std; int main () { int a = 5 cout << a--; return 0; } The output would still be 5, why is this ?
5 Réponses
+ 1
I think I figured it out, is it because I put it in console before decreasing it ? So now, if I used a again in another statement, it would then be 4 ?
+ 1
wouldn't you use --a in that case?
0
here post decrement operator is used so only in the next statement or in its next use of variable 'x' it will be decremented.
use of pre decrement operator would decrement it first only then other tasks would be performed.
0
the value decreases but you never output it's value after the post decrement. if you output the value one more time you will see the value is 4
0
Thank you both.