void main()
{
int a = 10;
int b;
b = (a++ - --a + ++a);
printf("value of b is %d",b);
b = a + b;
printf("Now value of b is %d",b);
}
echo47 said:There is no such problem in the C standard. It says an expression is not allowed to modify a variable more than once between sequence points. The statement b = (a++ - --a + ++a); violates that rule, so the results are undefined (anything could happen). To use such code in your program is a bug, even if it gives you the results you expected.
All C programmers should read the comp.lang.c FAQ. It's packed with excellent advise, including the topic we are currently discussing.
**broken link removed**
I also recommend using a more modern compiler than Turbo C. When I compile the example with MinGW, its warning messages identify several bugs, including the one we are currently discussing:
confusing.c:2: warning: return type of 'main' is not `int'
confusing.c: In function `main':
confusing.c:6: warning: operation on `a' may be undefined
confusing.c:6: warning: operation on `a' may be undefined
confusing.c:7: warning: implicit declaration of function `printf'
The solution to your confusion is simple: don't write obfuscated code!sawaak said:... how can it be, i m confuse
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?