Take the 2-minute tour ×

I am still trying to understand about doublepointers.

I do know how double pointers are usually used in most cases like

void foo(char **ptr)
 // blah

int main(void)
    char *ptr;

However i have no idea what one does differently than the other

int main(int argc, char **argv) //Double pointer

int main(int argc, char *argv[]) // Single
share|improve this question
This text explains pointers and has helped me alot. Might be interesting? cslibrary.stanford.edu/102/PointersAndMemory.pdf –  marko Oct 21 '11 at 21:36
possible duplicate of Should I use char** argv or char* argv[] in C? –  sidyll Oct 21 '11 at 21:53
add comment

2 Answers

up vote 2 down vote accepted

When used as a parameter to a function, an array designator [] is exactly the same as a pointer. The two declarations you have for main are in fact identical.

There are times when the two different syntaxes mean different things, but this isn't one of them.

In this case it means you have an array of pointers. Each pointer points to an array of characters. argv[0] is a pointer to the first char* string, argv[1] is a pointer to the second char* string, etc.

share|improve this answer
add comment

I feel your pain! It took me a long time to convince myself that I should treat them exactly the same.

argv[1] points to the first parameter, argv[argc-1] points to the final parameter. Yes, all you sharpshooters, that's true iff argc > 0.

That's my formula and I'm stickin' to it.

share|improve this answer
add comment

Your Answer


