-1

Possible Duplicate:
In C, are arrays pointers or used as pointers?

In C++, the default main function can have arguments like char* argv[]. What is the its difference from char** and char* argv[100] ?

Community
  • 1
  • 1
Strin
  • 677
  • 9
  • 15

3 Answers3

5

There is no difference in function parameters. In other situations, the first declares a pointer, the second declares an array.

Dirk Holsopple
  • 8,731
  • 1
  • 24
  • 37
  • There is a difference. In `char* [100]` you have some more information. – J.N. Oct 22 '12 at 13:20
  • @J.N. Not in function parameters. In function parameters, if the rightmost type is an array, the size is ignored. – Dirk Holsopple Oct 22 '12 at 13:24
  • @J.N. There's no difference between the two declarations when they appear in function declaration. – jrok Oct 22 '12 at 13:24
  • Indeed, I was wrong, though it would be useful to disambiguate. The difference only applies for array references. – J.N. Oct 22 '12 at 13:28
1

char** is a pointer to a pointer to a char.

The second char *argv[100] is an array of pointers to a char.

But when you pass an array to functions they decay to a pointer.

Lews Therin
  • 10,907
  • 4
  • 48
  • 72
1

char** argv: To elicit the same behavior as char* argv[100] you must dynamically allocate space to store char pointers. For example: (*argv) = new char[100];

Double pointers are a very flexible datatype unique to C++ which can grant insane speed and insane bugs. Generally if you know the size of your array, its best to avoid dynamic memory allocation.

Steve Barna
  • 1,378
  • 3
  • 13
  • 23