Pointer array pointer difference

Source: Internet
Author: User

An array pointer is a pointer to the address of the first element of an array. In essence, it is a pointer;

A pointer array is an array whose elements are pointers (for example, int * P [3], which defines three pointers: P [0], p [1], and P [2 ), its essence is array.

 

Array pointer (also called row pointer)
Define int (* P) [N];
() A high priority indicates that p is a pointer pointing to an integer one-dimensional array. The length of this one-dimensional array is N, or the step size of P. That is to say, when p + 1 is executed, P must span the length of N integer data.

 

To assign a two-dimensional array to a pointer, assign a value as follows:
Int A [3] [4];
INT (* P) [4]; // This statement defines an array pointer pointing to a one-dimensional array containing four elements.
P = A; // assign the first address of the Two-dimensional array to P, that is, a [0] Or & A [0] [0].
P ++; // after the statement is executed, that is, P = p + 1; p spans Row A [0] [] pointing to row A [1] []

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

 

 

Pointer Array

 

It can be understood as a two-dimensional array, but it is different.

Define int * P [N];
[] High priority. It is first combined with P to form an array, and then int * indicates that this is an integer pointer array, which has n Array elements of pointer type. The execution of p + 1 here is incorrect, so the value assignment is also incorrect: 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 store variable addresses. But it can be like this * P = A; here * P represents the value of the first element of the pointer array and the value of the first address of.

 

 

The most frequent use of pointer arrays is to store character arrays of different lengths.

 

char *week[]={"Monday","tuesday",“wednesday”,“thursday”,“Friday”};

Differences between pointer arrays and Arrays

 

The most frequent use of pointer arrays is to store character arrays of different lengths.

 

 

 

 

 

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.