I just found a little confusion when using the increment operator in an array of pointers.
Code 1:
int main(void) { char *array[] = {"howdy", "mani"}; printf("%s", *(++array)); return 0; }
When compiling, gcc throws the known error "lvalue required as an increment operand".
But, when I compile the code below, it does not show errors !!! Why?
Codex2:
int main(int argc, char *argv[]) { printf("%s",*(++argv)); return 0; }
In both cases, I incremented the pointer array. Therefore, it must be done in this way.
char *array[] = {"howdy","mani"}; char **pointer = array; printf("%s",*(++pointer));
But why does code2 not show errors?
source share