C++ x+=1 x++ and x = x +1 are not the same? -
this question has answer here:
- post-increment , pre-increment concept? 9 answers
i can not grasp concept how these statements produce different values. far know x+=1, means x = x + 1. know x++ should equivalent x + 1.
i've searched topic , found posts ask same question, posts answered stating statements/expressions same, different result due code mistake. example provide don't see how there code mistake please explain, thank you.
int x = 0; x++;
x should 1 @ point because x++ adds 1 x.
so why if assign x 0, , proceed code "cout << x++;" value of 0 on screen?!. how x++ become 0 if x++ equal x+1 , if x 0 1+0=1? i've been told due ++ being put after x, why matter if dealing addition 1 + 0 same 0 + 1?
cout << x++;
outputs value of x
before increment using postfix increment operator.
cout << ++x;
expect.
Comments
Post a Comment