For the understanding that the array name is a pointer in the C language

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.