I also read on wikipedia that double indirection (**) is higher number of pointer dereferences, it will come at a performance penalty. Am I right in assuming that this would be a compelling reason to not use ** when you have a choice of using only *?
To take things further and bring up a "real world" example, if you will, the following is something I looked up.
1 2 3 4 5 6 7 8 9
void Foo1(Foo a[ ], unsigned n) {
int i;
char buffer[200];
for (i = 0; i < n; i++)
{
to_string(&a[i], buffer);
printf("%s\n", buffer);
}
}
vs
1 2 3 4 5 6 7 8 9 10 11
void Foo2(Foo* a[ ], unsigned n)
{
int i;
char buffer[200];
for (i = 0; i < n; i++)
{
to_string(a[i], buffer);
printf("%s\n", buffer);
}
}
From the above, the first points to a const array, that can be changed and as per http://en.wikipedia.org/wiki/Const_correctness, can be used to change the contents of a[] (in the first example), but in the second you cannot change the contents, only get the items from them. I also say this because this line of code:
An array is a constant pointer (in that the pointer cannot be changed to point at something else). Not a pointer to a constant object (in that the object's value cannot be changed).
to_string() requires that you pass a pointer to a Foo class. The first example our array stores objects of type 'Foo', while in the second the array stores pointers to objects of type 'Foo'.
So the & is used to pass the address of the object 'Foo' in the first, but in the second it's not needed because the array is of addresses already.