Array pointers and array of pointers

Source: Internet
Author: User

Array pointers (also known as row pointers)

Definition: Int (*p) [n];

Note: () high priority, first of all, that P is a pointer to an integer one-dimensional array, the length of the one-dimensional array is n, it can be said that the step of P. In other words, when p+1 is executed, p spans n integer data lengths.

To illustrate:

int a[3][4];

int (*p) [4];

p=a;//assigns the first address of a two-dimensional array to p, i.e. a[0] or &a[0][0]

p++;//The statement executes, P=p+1;p crosses a[0][] and points to a[1][]

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

Array of pointers

Definition: int *p[n];

Note: [] high priority, first combined with p to form an array, and then by int* that this is an array of pointers, it is an array element with n pointer types. When P+1 is executed, p points to the next array element, and the assignment of p=a is wrong, because P is not represented, only p[0],p[1],...., P[n], and they are the address where the pointer variable can be used to hold the variable. But this means that *p=a,*p represents the value of the first element of the pointer array, the first address of a.

To illustrate:

int *p[3];

int a[3][4];

for (int i=0;i<3;i++)

P[i]=a[i];//int *p[3] Indicates that a one-dimensional array holds three pointer variables, respectively p[0],p[1],p[2], so assign values separately.

The difference between an array pointer and an array of pointers

An array pointer is just a pointer variable, similar to a two-dimensional array that occupies the storage space of a pointer in memory.

The pointer array is an array that contains multiple pointer variables that exist within the form of an array, occupying multiple pointer storage spaces.

Http://www.cnblogs.com/hongcha717/archive/2010/10/24/1859780.html

Array pointers and array 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.