Consider an array.
char arr[10];
When we find sizeof(arr) ---> Output is 10, arr is treated as
an object of 10 chars.
When we say arr+1, ---> arr is treated as a pointer to char.
Why is this anomalous behaviour ?
Also, why arr is called a non modifiable lvalue ?
why arr++ not allowed but arr+1 is allowed ?
Instead of all the bandying about of legalities, take a look at
what is actually going on in a typical system, and then remember
that the legalities etc. are designed to tie everything together on
all systems suitable for the language.
When arr[10] is declared, the compiler assigns a space somewhere,
sufficient to hold 10 chars. It remembers where that space is, and
arranges not to reassign it (at least until it goes out of scope).
That remembering requires a number, call it P. P is going to be
used to create a pointer to the first item in arr whenever needed.
We can't modify P. It just exists as a number. If we did we would
have forgotten where arr lives. We can modify what P points to,
because that is the first item in arr, and that has a home.
If we write arr++ we are trying to modify P. That is not allowed.
The value of the expression arr++ is P+1, which is allowable, but
we can't get it via arr++. So we can write P+1, to get the
unmodifiable pointer to the 2nd item in arr.
What we can do is to declare a pointer, initialize it to point to
arr, and then use ++ on that.
char *ptr = arr;
ptr++;