In said:
m said:
main(int argc, char *argv[])
the second parameter to function main takes a pointer to an array.
No it doesn't. It takes a pointer to a pointer to char. That's why an
equivalent version is:
int main (int argc, char **argv)
However, the equivalent version is losing a semantic clue: that argv is
supposed to point to the first pointer of an array of pointers. It makes
no difference to the compiler, but it does make a difference to the
human reader.
Furthermore it is quite idiomatic to refer to a pointer to the first
element of an array as a pointer to an array, as long as it is clear that
its type is not pointer to array. Example from the C standard itself:
2 The strcpy function copies the string pointed to by s2 (including
the terminating null character) into the array pointed to by
^^^^^^^^^^^^^^^^^^^^^^^
s1. If copying takes place between objects that overlap, the
^^
behavior is undefined.
The case of main being so well known, most advanced programmers prefer
**argv because it is easier to type than *argv[]. However, in any other
function interface, I would recommend *argv[] instead of **argv, due to
the semantic clue I was talking above. It's much less of an issue when
dealing with plain arrays, so I wouldn't bother with a[] instead of *p.
Dan