cpointersparametersfunction-declaration

char** v *char[] in C


As I read through C code, I often times see this:

int main(int argc, char **argv)

but I always learned to do this:

int main(int argc, char *argv[])

So, why would I use one over the other? I know they're technically different, but I don't see quite why I'd use one as opposed to the other.

Thanks in advance.


Solution

  • Functionally, for the purposes of access to the arguments, those two notations are equivalent.

    The [] notation may have a marginal benefit of distinguishing between a pointer to a single element and a pointer to an array; the char** can be misread as an out-parameter of type char*.

    Unlikely with main()'s argv though.