Reputation: 650
i have this code snippets
const int col= 5;const int row= 5;
int a[row][col] = {0};
int (*p)[col] ;
p = a;
And these statements print the same address
cout <<p;
cout << endl;
cout << *p;
in my opinion since p
points to an array of 5 ints
, dereferencing it
should give the first value which doesn't seem to be the case.
help!
Upvotes: 0
Views: 381
Reputation: 254771
since
p
points to an array of 5ints
That much is correct.
dereferencing it should give the first value
No, it's type is "pointer to array"; dereferencing that gives "array", which decays to an int*
pointer when you do just about anything with it - including printing it.
If you had a pointer to int
int * p = a;
then *p
would indeed give the first array element.
Upvotes: 6