char pointer

Hi all,

I have a doubt, may be it sounds foolish..

in main function the second argument is pointer to a char array. (char *argv[] or char ** argv). I tried to use a two dimensonal char array instead. It compiled but when i tried to output the value it is printing garbage value.

code is here
int main(int argc, char argv[][])
{
cout<<"argv"<< argv[0]<<endl;

}

please correct me...

Thanks in advance
Viji.r
That's because you changed the element type. The array must be an array of (char*). You can declare it as one of the following:

char* argv[] char** argv

The first is simply more explicit that it is an unbounded array of char pointers, but in either case argv is a pointer to (char*).

Well, there is one other difference...
With the first form you are not permitted to modify argv (eg. argv++) but with the second you are.

Hope this helps.
Topic archived. No new replies allowed.