Array pointers and arrays of pointers

Source: Internet
Author: User

Array of pointers

int *p[10];

[] High priority, the first combination with P as an array, and then by int* that this is an integer pointer array, which has 10 pointer-type array elements. The execution of p+1 here is wrong, so the assignment is also wrong: P=a, because P is an unknown representation, only p[0], p[1], p[2]...p[n-1], and they are pointer variables that can be used to hold variable addresses. But can be so *p=a; Here *p represents the value of the first element of the pointer array, the value of the first address of a.

To assign a two-dimensional array to a pointer array:
int *p[3];
int a[3][4];
for (i=0;i<3;i++)
P[i]=a[i];
Here int *p[3] indicates that a one-dimensional array holds three pointer variables, respectively p[0], p[1], p[2]
So you have to assign values separately.

Array pointers

int (*p) [10]; The first point is that P is a pointer to a one-dimensional array of integers, and the length of the one-dimensional array is n, or the step of P. In other words, when executing p+1, p crosses the length of n integer data.

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.

Array pointers and arrays of pointers

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.