Why does this program display 90, shouldn't it display 99?Code:#include <stdio.h> int main(){ int x = 10; printf("%d", x*=x--); return 0; }
Why does this program display 90, shouldn't it display 99?Code:#include <stdio.h> int main(){ int x = 10; printf("%d", x*=x--); return 0; }
Expressions
Because using a variable when it also has side effects is undefined behaviour.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Learn how to turn on compiler warnings. For your example, the compiler will help you. For example GCC says the following:
Code:main.c:7:19: warning: operation on 'x' may be undefined [-Wsequence-point] printf("%d", x*=x--);