As we all know, the array name in C is a pointer, such as the following code
#include <iostream>
using namespace Std;
int main ()
{
int a[4]={1,2,3,4};
for (int i=0;i<4;i++)
{
cout<<* (a+i);//* (A+i) and a[i] are equivalent.
cout<<endl;
}
return 0;
}
But look at the code below.
#include <iostream>
using namespace Std;
int main ()
{
int a[4]={1,2,3,4};
cout<< "Array Length" <<sizeof (a) <<endl;
int *p;
cout<< "The length of the Shaping pointer is:" <<sizeof (P) <<endl;
P=a;
cout<< "Pointer to a shaped array after the length of:" <<sizeof (P) <<endl;
return 0;
}
The result of the operation is: the length of the array is 16
The length of the Shaping pointer is: 4
The length of the pointer to the shaped array is: 4
*********************************
The question is: Since the array name A is a pointer, why does sizeof (a) and sizeof (p) get a different result? Does it mean that the array name is not just pointers?
I understand that the array name is a pointer, and it is a constant pointer, and sizeof a long pointer and a pointer variable of the same type get the result is not the same.
For the understanding that the array name is a pointer in the C language