0
How it works.. printf("number %d",b=(a++,a++)); printf("b=%d",b);
how the expression in 1st printf evaluated and how this all work ..with output
2 Answers
+ 1
The tricky part of the snippet that you have provided is b=(a++, a++), Let me explain it by expanding upon the snippet itself.
Consider the following version
1. int a = 1;
2. int b = 2;
3.
4. // b = (Expr1, Expr2)
5. b = (a++, a++);
6. printf("b is â
d\n", b);
7. printf("a is %d", a);
In line 4, what we are going to expect to being assigned to variable b is the Expr1 and the rest is discarded, that is, b = a++. Both Expr1 and Expr2 are evaluated before assignment, so, at the end of the day, the result of the two print statements would be as
b is 2
a is 3
0
Would you mind posting more of the code?