On pointer array and array pointers

Source: Internet
Author: User

Often encounter these two concepts, it is easy to confuse, here carefully summed up.

pointer array : An array whose elements are pointers. the number of bytes that the array occupies is determined by the array itself.

array pointer : is a pointer that points to an array. the 32-bit system is always 4 bytes.

To illustrate:

1) int *p1[n];
2) int (*P2) [n];

1) The priority of "[]" is higher than "*". P1 is first combined with "[]" to form the definition of an array, with the array named P1,int * decorated with the contents of the array, that is, each element of the array. That is, p1 is a pointer array that contains n pointers to data of type int.

2) The priority of "()" is higher than "[]", "*" and P2 constitute a pointer definition, and the pointer variable named P2,int modifies the contents of the array, that is, each element of the array. The array does not have a name here and is an anonymous array. That is, p2 is an array pointer to an array that contains n data of type int.

To assign a two-dimensional array to a pointer, you should assign this value:
int a[3][4];
int (*p) [4]; The statement defines an array pointer to a one-dimensional array with 4 elements.
P=a; Assign the first address of the two-dimensional array to p, i.e. a[0] or &a[0][0]
p++; After the statement executes, that is, P=p+1;p crosses line a[0][] points to the line a[1][]

So an array pointer is also called a pointer to a one-dimensional array, also known as a row pointer.


On pointer array and array pointers

Related Article

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.