I think I will get 12, not 7.
w++, then w will be 4, which is 100, and w++, w will be 8, 1000;
so w++|z++ will be 100|1000 = 1100 will be 12.
what’s wrong with me?
int main()
{
int w=3, z=7;
printf("%d\n", w++|z++);
}
The problem is that by using
w++|z++, you’re first using the value ofwand ORing that by the current value ofz, then incrementing each. Use++w|++zinstead, and the numbers will first be incremented, then used.The same can be done with
--xandx--. For more information, see this relevant question.