First, int a=61,i=-5;
gives us a
= 61 and i
= −5.
Then the initial clause of the for
, int *p=&i
, sets p
to point to i
. From this point on, we may take *p
as equivalent to i
.
Then the controlling expression of the for
, (a++,(*p)++)?(++(*p),(a--)-1):((*p)+=3,a-1)
, is evaluated. Its highest/outermost operator is ? :
. The first operand of that (a++,(*p)++)
is evaluated. This sets a
to 62 and i
to −4. The result, from the comma operator, is the value of i
(*p
) before the increment, so it is −5.
That −5 is used to select in the ? :
operation. Since it is not zero, the operand between ?
and :
is evaluated. That is (++(*p),(a--)-1)
. This sets i
to −3 and a
to 61. The value is a
before the increment minus 1, which is 62−1 = 61. Thus the expression is non-zero, indicating the loop should continue.
Program control flows into the body of the for
, where --a
decrements a
to 60.
Then the printf
shows us that a
is 60 and i
is −3.
The test *p>3
is false, since i
is −3, so the continue
is executed.
This causes the iteration expression of the for
to be evaluated. That is (*p)++
, so i
is set to −2.
Then the controlling expression is evaluated. As before, the first operand of ? :
, (a++,(*p)++)
, is evaluated. This sets a
to 61 and i
to −1, and the value of the expression is −2.
Again the second operand,(++(*p),(a--)-1), is evaluated. This sets i
to 0 and a
to 60, and its value is 59.
Inside the body, --a
decrements a
to 59.
The printf
shows us a
is 59 and i
is 0.
Again *p>3
is false, so the continue
is executed.
This takes control to the iteration expression, (*p)++
, which sets i
to 1.
Then the controlling expression is evaluated, starting with the first operand of ? :
. Now (a++,(*p)++)
sets a
to 60 and i
to 2, and the expression value is 1.
The second operand of ? :
,(++(*p),(a--)-1), is evaluated, which sets i
to 3 and a
to 59, and the expression value is 59, so the loop continues.
--a
sets a to 58.
The printf
shows us a
is 58 and i
is 3.
Again *p>3
is false, so the continue
is executed.
This takes control to the iteration expression, (*p)++
, which sets i
to 4.
Then the controlling expression is evaluated, starting with the first operand of ? :
. Now (a++,(*p)++)
sets a
to 59 and i
to 5, and the expression value is 4.
The second operand of ? :
,(++(*p),(a--)-1), is evaluated, which sets i
to 6 and a
to 58, and the expression value is 58, so the loop continues.
--a
sets a to 57.
The printf
shows us a
is 57 and i
is 6.
Now *p>3
is true, so the statements inside the if
are executed.
These start with a=(!(--a)&&a++)?3:2;
. Here --a
sets a
to 56 and evaluates to that value. Then !
inverts it logically, producing 0. This causes the &&
to produce 0 without evaluating its second operand. So this first operand of ? :
is 0, which results in the third operand of ? :
being evaluated. That operand is 2, so that is the value assigned to a
.
The final printf
shows us the current value of a
, 2.