Answer: B
https://en.wikipedia.org/wiki/Sequence_point#Sequence_points_in_C_and_C++
Before a function is entered in a function call. The order in which the arguments are evaluated is not specified, but this sequence point means that all of their side effects are complete before the function is entered. In the expression f(i++) + g(j++) + h(k++)
, f
is called with a parameter of the original value of i
, but i
is incremented before entering the body of f
. Similarly, j
and k
are updated before entering g
and h
respectively. However, it is not specified in which order f()
, g()
, h()
are executed, nor in which order i
, j
, k
are incremented. If the body of f
accesses the variables j
and k
, it might find both, neither, or just one of them to have been incremented. (The function call f(a,b,c)
is not a use of the comma operator; the order of evaluation for a
, b
, and c
is unspecified.)
arr
7 |
8 |
9 |
8 |
arr + 3 |
arr + 2 |
arr + 0 |
arr + 1 |
ap
arr + 3 |
arr + 2 |
arr + 1 |
arr + 0 |
Precedence ( [] = → = ++ post = . struct member access) > (++ pre) > (- subtraction, not unary minus) .
printf("%d ", ap[++pp[2]->i-6]->i++);
pp[2] = (arr + 1); (arr + 1) → i = 8; ++8 = 9; 9 – 6 = 3;
ap[3] = arr; arr → i = 7; 7++;
Printed: 7
Side effects:
arr
8 |
9 |
9 |
8 |
arr + 3 |
arr + 2 |
arr + 0 |
arr + 1 |
printf("%d ", pp[1]++->p++->i);
pp[1] = (arr + 2); (arr + 2)++; (arr + 2) → p = (arr + 0); (arr + 0)++; (arr + 0) → i = 8
Printed: 8
Side effects:
arr
8 |
9 |
9 |
8 |
arr + 3 |
arr + 2 |
arr + 1 |
arr + 1 |
ap
arr + 3 |
arr + 3 |
arr + 1 |
arr + 0 |
printf("%d", ++arr[2].p->i);
arr[2].p = (arr + 1); (arr + 1) → i = 9; ++9 = 10 (immediate side effect, pre increment)
Printed: 10