I am getting \"lvalue required as increment operand\" while doing *++a
. Where I am going wrong? I thought it will be equivalent to *(a+1)
. This beh
++a
and a + 1
are not equivalent. ++a
is the same as a = a + 1
, i.e it attempts to modify a
and requires a
to be a modifiable lvalue. Arrays are not modifiable lvalues, which is why you cannot do ++a
with an array.
argv
declaration in main
parameter list is not an array, which is why you can do ++argv
. When you use a[]
declaration in function parameter list, this is just syntactic sugar for pointer declaration. I.e.
int main(int argc, char *argv[])
is equivalent to
int main(int argc, char **argv)
But when you declare an array as a local variable (as in your question), it is indeed a true array, not a pointer. It cannot be "incremented".