I\'m reading a section from C Primer Plus about command-line argument argv
and I\'m having difficulty understanding this sentence.
It says that,
Directly quoting from C11
, chapter §5.1.2.2.1/p2, program startup, (emphasis mine)
int main(int argc, char *argv[]) { /* ... */ }
[...] If the value of
argc
is greater than zero, the array membersargv[0]
throughargv[argc-1]
inclusive shall contain pointers to strings, [...]
and
[...] and the strings pointed to by the
argv
array [...]
So, basically, argv
is a pointer to the first element of an array of strings note. This can be made clearer from the alternative form,
int main(int argc, char **argv) { /* ... */ }
You can rephrase that as pointer to the first element of an array of pointers to the first element of null-terminated char
arrays, but I'd prefer to stick to strings .
NOTE:
To clarify the usage of "pointer to the first element of an array" in above answer, following §6.3.2.1/p3
Except when it is the operand of the
sizeof
operator, the_Alignof
operator, or the unary&
operator, or is a string literal used to initialize an array, an expression that has type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points to the initial element of the array object and is not an lvalue. [...]