Re: well-defined terminology versus generally accepted terminology regarding pointers and arrays
"TJorgenson" <tjorgenson@infinera.com> wrote in message
news:b7ba6dc2-b2c4-4481-bfb4->9360a7bbb62e@k3g2000prl.googlegroups.com...
On Apr 22, 10:44 am, "Paul" <pchris...@yahoo.co.uk> wrote:
But it can be shown that it's a pointer to another pointer like so?
int arr[12];
int (*p)[12] = &arr;
**p = 33;
std::cout<<arr[0];
In the expression **p = 33, there are two asterisks. This pointer is
being
dereferenced twice , this could not be possible if it did not point to
another pointer object.
Try compiling and running this on your favorite platform:
int main()
{
int arr[12];
int (*p)[12] = &arr;
**p = 33;
std::cout<<arr[0] << std::endl;
std::cout << "p[" << p << "] *p[" << *p << "] **p[" << **p << "]"
<< std::endl;
}
The output on my Windows box is as follows:
33
p[0012FF34] *p[0012FF34] **p[33]
Note that p and *p have the same value (i.e. the same address). This
kind blows your "this is a pointer to another pointer object" theory
out of the water doesn't it? Where is this "phantom pointer" that "p"
supposedly points to? How can it have the same address as "p"?
This proves that *p does not dereference the same object as **p. So you tell
me what does p point to, the obejct dereferenced by *p or the object
referenced by **p?
With an array of ints, the following identifiers all have the same value:
int arr[10];
int* p= arr;
int (*pp)[10] = &arr;
the value of arr, p and pp all have the same value
if(*p == *arr == **pp)
std::cout<< "They're all the same, note the different level of indirection
for **pp";
p is a pointer that, when dereferenced, accesses the array.
pp is a pointer that, when dereferenced, does not access the array.
I say p points to the array of integers.
pp points to something else, I have said it was an array-type object, I have
said it is a pointer with a different level of indirection. Whatever the
object/s are that hold the values 0012FF34 in your example it is certainly
not the array of integer objects.