Help understanding char* argv[]

Jul 27, 2011 at 8:42pm
I have read that argv is an abbreviation for ``argument vector''. It is the traditional name for a pointer to an array of string pointers passed to a C program's main function;

So then why is argv written as "char* argv[]"? That tells me that argv is an array of pointers to chars. Shouldn't it be written as "string* (*argv)[]"? Can anyone help clear this up?
Jul 27, 2011 at 9:16pm
Basically you can pass parameters to a program, say u open a file with paint, it sends location.

Or if you run a terminal program java -jar filename.

Remember a string literal in an array is a 2 dimensional array.
Last edited on Jul 27, 2011 at 9:17pm
Jul 28, 2011 at 4:13am
I understand how to use argv, just not why it works.
Jul 28, 2011 at 4:16am
That tells me that argv is an array of pointers to chars.

Yes, that's what it is. Pointers to chars, char*, are C-style strings. They're arrays of characters with a terminating '\0' character (ASCII 0) that says when the "string" ends.
Last edited on Jul 28, 2011 at 4:17am
Jul 28, 2011 at 3:54pm
Well that would take care of the strings, but the definition for argv says that it is a pointer to an array of pointers to chars, not and array of pointers to chars. Shouldn't it be written as char* (*argv)[]
Jul 28, 2011 at 4:52pm
but the definition for argv says that it is a pointer to an array of pointers to chars

No it doesn't. That definition is wrong. argv is an array of C-style strings. argv can also be declared as char** argv.
Topic archived. No new replies allowed.