EXAMPLE 7 The grouping of an expression does not completely determine its evaluation. In the following fragment:
#include <stdio.h> int sum; char *p; /* ... */ sum = sum * 10 - '0' + (*p++ = getchar());
the expression statement is grouped as if it were written as
sum = (((sum * 10) - '0') + ((*(p++)) = (getchar())));
but the actual increment of p can occur at any time between the previous sequence point and the next sequence point (the ; ), and the call to getchar can occur at any point prior to the need of its returned value.
So basically I understand this as unspecified behavior - either *p = getchar(); p++;
OR p++; *p = getchar()
. Note that the ;
implies a sequence point, but there are no other sequence points in the whole expression.
So this syntax is useless. And, pretty much, ++ and -- for pointer assignment is useless. Right?