In the C standard ISO/IEC 9899:2018 (C18), §5.1.2.2.1 - "Program startup", is written:
2 - If they are declared, the parameters to the main function shall obey the following constraints:
— argv[argc] shall be a null pointer.
My Question is:
- Why
char *argv[argc]
/char **argv
shall be/ is a pointer toNULL
?
This is what doesn´t make sense to me. argv[]
is an array of pointers pointing to char
. argv
is a pointer to an array of pointers, pointing to char
. Even if there are no flags given by the call, the pointer shouldn´t turn to a pointer to NULL
.
Isn´t char* argv[]
an array of pointers to char
and char **argv
a nested pointer to char
pointers? How can a nested pointer to char
(char**
) be a pointer to NULL
?
I have read the answers to argv[argc] ==? where the above-mentioned phrase from the standard is quoted as answers and also questioned to @pmg´s answer, who gave me the answer:
independent of the names used, by the c specification char *argv[argc] declares an array named argv capable of holding argc pointers to char. When passed to a function, the array gets converted to a pointer to its 1st element (so a pointer to pointer to char [this is why it is usual to see main(int argc, char **argv)]) losing information about size (char *a[10] has 10 elements; char **a is a pointer --- if the pointer points to an array, there is no way of knowing how many elements the underlying array has).
but unfortunately despite the humble effort, I still can´t understand why a pointer to pointer (nested pointer) to char
(char**
) turns into a pointer to NULL
.
The answers to Is argv[argc] equal to NULL Pointer also do not answer why it shall be a pointer to NULL
, only that is a pointer to NULL
while quoting the above statement of the standard.
Thanks in advance.