There is something that I saw and wanted to check if it is really wrong, as I thought. In the second edition of The C Programming Language 2nd ED by Brian Kernighan and Denis Ritchie, in the section of 5.2 Complicated Declarations, in page 109, it is written so, isn't it false?
char **argv
argv: pointer to char

Isn't it pointer to char* or pointer to pointer of char?

Thanks!

Recommended Answers

All 2 Replies

sorry but the book is correct. It is a double pointer because it represents a set of strings. For example it might be

/* Effective what it is. Not real code */
argv[0]="this program";
argv[1]="option";
argv[2]="another option";

It is perfectly correct to ask stuff like what is the eighth character in the second string e.g. char x=argv[1][7]; Also note that you are not responsible to freeing the memory for argv, and that argc tells you the number of strings, but you have to test the length of each one (strlen) if you want to use them reliably.

Finally, many people like to write it int main(int argc,char* argv[]) and that is perfectly acceptable as well.

There is something that I saw and wanted to check if it is really wrong, as I thought. In the second edition of The C Programming Language 2nd ED by Brian Kernighan and Denis Ritchie, in the section of 5.2 Complicated Declarations, in page 109, it is written so, isn't it false?
char **argv
argv: pointer to char

Isn't it pointer to char* or pointer to pointer of char?

K&R, chapter 5:

Since argv is a pointer to an array of pointers...
...argv, which is a pointer to pointer to char...

Where is "argv: pointer to char" in K&R?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.