C language array pointer and pointer array, C language array pointer

Source: Internet
Author: User

C language array pointer and pointer array, C language array pointer

1. array pointer:The pointer to an array is an array pointer.

Let's take a look at the following code:

# Include <stdio. h> int main (void) {int m [10]; printf ("m = % p, & m = % p \ n", m, & m ); printf ("m + 1 = % p, & m + 1 = % p \ n", m + 1, & m + 1); return 0 ;}

The result obtained by running the above Code is as follows:

In the code above, & m is a pointer to an array, that is, the array pointer. It is completely equal in the value of m, all pointing to the starting address of the same memory segment. However, their types are indeed different. M is a pointer of the int * type, and m points to an array such as int m [10]. Therefore, m + 1 is equivalent to adding sizeof (int ), it can be calculated from (0x0028FEFC-0x0028FEF8) = 4; while & m + 1 is equivalent to adding sizeof (int [10]), from calculation in (0x0028FF20-0x0028FEF8) = 40.

It can be defined as follows:

Int (* p) [10] = & m; here p is an array pointer, And here (* p) parentheses are required,() Has a higher priority than []Therefore, p is a pointer first, and then points to an array of int [10.

 

2. pointer array:An array composed of multiple pointers is a pointer array.

Int * p [10]; here we can compare it with the above array pointer. P is an array first, and the type is Pointer. Therefore, p is a pointer array (containing 10 pointers, such as p [0] and p [1].. P [9], each pointer type is int *), and each of its variables can be used to store the address.

 

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.