Adam Templeton Adam Templeton - 5 months ago 41
C++ Question

C++ Pointer Defererence Declaration Syntax

Incredibly new to C++, and have a (probably fairly dumb) question:

I've seen the

operator (which I understand is dereferencing a dereference) used in both contexts:

char **arglist

char** arglist

Is there a meaningful difference between the syntaxes, or are they both accomplishing the same thing?


They are exactly the same. But they are not "dereferencing a dereference" in this case, they define a pointer to pointer to char.

I personally prefer char** arglist because the ** is like a part of the type and it's like:

type var_name; // where `type` is `char**` and `var_name` is arglist

BUT, on the other side, it may be misleading, because the following:

char** arglist1, arglist2;

defines char** variable named arglist1, AND a char variable named arglist2.

So, in order to define 2 variables with type char**, you need

char **arglist1, **arglist2;


char** arglist1, **arglist2;

or, of cource:

char**arglist1, **arglist2;

all three are the same, it's a matter of personal preference.