You have probably misunderstood the post-increment
operator which is very common among the beginners, so don't worry. Over time you'll get it right.
Take a look at the word post-increment
. There is a post
word in it which generally signifies after
. It means that the increment will happen after
everything else has been executed. This is how I used to remember it.
So, if you take a look at your program now -
int main()
{
int w=3, z=7;
printf("%d\n", w++|z++);
}
then it will become clear that after the printf
function itself has been executed, the increment will happen. So you will get the value of w
and z
as 3
and 7
, respectively in the evaluation of the second argument expression of printf
.
The official C++11 standard, (§5.2.6, final version) says -
The value of a postfix ++ expression is the value of its operand. [Note:the value obtained is a copy of the original value — end note]
So that means the value of the postfix w++
expression, is the value of the operand itself, that is, the value of the w
, which is 3 and the value of the second expression z++
will be 7. These values will then be used in the calculation of 3|7
and after that, the variables will be incremented.