I just found a little confusion while using increment operator in pointer array.
Code 1:
int main(void) {
char *array[] = {"howdy", "mani"};
printf("%s", *(++array));
return 0;
}
While compiling, gcc throws a well known error "lvalue required as increment operand".
But, when I compile the below code it shows no error!!! Why?
Code2:
int main(int argc, char *argv[]) {
printf("%s",*(++argv));
return 0;
}
In both cases, I have been incrementing an array of pointer. So, it should be done by this way.
char *array[] = {"howdy","mani"};
char **pointer = array;
printf("%s",*(++pointer));
But, why code2 shows no error?
char *argv[]equivalent tochar **argvbut not so with a user-defined pointer to array..char *array[]is an array of pointers. A function argumentchar *argv[]is actually achar **argv. C11 draft standard6.7.6.3 Function declarators (including prototypes), Section 7 A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’[...].char *argv[]passed tomain()decays tochar **, not so with your direct use of*array[]inmain()