int val = 5;
printf(\"%d\",++val++); //gives compilation error : \'++\' needs l-value
int *p = &val;
printf(\"%d\",++*p++); //no error
Could
int j = ++val++; //gives compilation error
That because you cannot pre-increment an rvalue
. ++val++
is interpreted as ++(val++)
because post-increment operator has higher precedence than pre-increment operator. val++
returns an rvalue
and pre-increment operator requires its operand to be an lvalue
. :)
int k = ++*p++; //no error
++*p++
is interpreted as ++(*(p++))
, which is perfectly valid.