This might be a bit of a basic question, but what is the difference between writing char * [] and char **? For example, in main,I can have a char * argv[]. Alternatively I can use char ** argv. I assume there’s got to be some kind of difference between the two notations.
Share
Under the circumstances, there’s no difference at all. If you try to use an array type as a function parameter, the compiler will “adjust” that to a pointer type instead (i.e.,
T a[x]as a function parameter means exactly the same thing as:T *a).Under the right circumstances (i.e., not as a function parameter), there can be a difference between using array and pointer notation though. One common one is in an
externdeclaration. For example, let’s assume we have one file that contains something like:and we want to make that visible in another file. This will work:
but this will not:
If we make it an array of pointers instead:
…the same remains true — declaring an extern array works fine, but declaring an extern pointer does not: