int main(){
int a[10][10];
int **ptr =(int **)a;
cout<<a<<endl<<ptr<<endl;
cout<<*a<<endl<<*ptr<<endl;
return 0;
}
Output of this code on my computer is
0021FC20
0021FC20
0021FC20
CCCCCCCC
Why is “a” equal to “*a“?
why isn’t *a equal to *ptr?
Since you cannot print an array,
ais implicitly converted fromint[10][10]toint(*)[10]. So what actually gets printed instead ofais a pointer to the first line ofa.*ais the first line of the array, and that in turn gets converted to a pointer to the first element.Since an array has the same address as its first element, you get the same value twice.