Expressions of array type such as x
cannot be the operand of the ++
operator.
There's no storage set aside for a variable x
apart from the array elements themselves (x[0]
through x[99]
); IOW, there's nothing in memory to which we can apply the autoincrement operator. x
will "decay" to a pointer value in most circumstances, but that pointer value isn't stored anywhere that you can modify it.
As others have shown, you can declare a separate pointer variable and use that instead of x
:
int *p = x;
for ( i = 0; i < 100; i++ )
*p++ = i;
Postfix ++
has higher precedence than unary *
, so *p++
will be parsed as *(p++)
.
Although frankly the following will work just as well:
for ( i = 0; i < 100; i++ )
x[i] = i;