Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

double star before a variable? * *

Status
Not open for further replies.

dnnymak

MIS
Sep 19, 2004
9
US
I am trying to read a .pgm file into an array. The code I was given has the following variable declaration:

int **image;

what does the "**" mean before image?


thanks,
Dnnymak
 
There is a very simple rule to read (all!) C/C++ declarators.

Let's suppose we see this declarator (**image) in an expression. What can we dereference with * operator in C/C++ language? Only pointers, of course. Well, image is a pointer. We have two * operators (right to left binding). So the result of the 1st (right side;) op must be dereferenced i.e. it's a pointer too. OK, image var must be pointer to pointer.

Now see on a simple type starting this declaration (char). Result of two dereferencing ops (*(*)) must be char.

Conclusion: we have (we declare) pointer to pointer to char!

Try to apply this rule in other cases (for typedefs too). It works...
 
There is also a minor point of style. Some people write

char** image, wow;

Others write

char **image, wow;

They both mean the same thing but the former implies that wow is a char** when it is actually a char. When your in the depths of debugging, such declarations don't help. With the latter, it is obvious that it is a char. If you are going to use the first format, declare your variables separately

char** image;
char wow;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top