Question about array address retrieval in C Language

Source: Internet
Author: User

For questions about array address retrieval in C language, see supplement: Define an array INT8U a [4]; then forcibly convert it (you do not need to consider the size of the end temporarily ), there are three writing methods: 1, * (INT32U *) a; 2, * (INT32U *) (& a [0]); 3, * (INT32U *) (& ); are the 3rd statements correct? I think it is wrong, but why is there no problem in both compiling and running? If it is correct, how can we understand it? Answer: (a) is the first address of a one-dimensional array, (& a [0]) Is it equal to (a) the first address of a unique array, the unique width is that the first address value of the number of elements in array a is the same, and you have made a forced conversion. Therefore, we cannot see the difference. If you use the following method, we can see the difference between printf ("% x", (void *) (a + 1); // = & a [1] printf ("% x ", (void *) (& a [0] + 1); // ==& a [1] printf ("% x", (void *) (& a + 1); // = & a [sizeof (a) + 1] Question, I define a one-dimensional array, how to understand (&) is it the first address of the Binary-only array? Is it the default processing of the compiler? A is just the first address of an array, not a pointer variable, but it is equivalent to a unique pointer, the system will let the pointer obtained by taking the array as an element. The first address of the pointer has not changed, but when performing address operations such as + 1, it directly uses the entire array as the element to move the pointer to the back. This behavior shows that it is a unique layer more than this a and should be the rule processed by the compiler. The body is further summarized as follows: int I; I is only a 0-unique (only one element) int * p = & I; in this case, p can be regarded as a unique layer than I, that is, it can be regarded as a unique array, point to 0 unique element int ** p2 = & p; it can be seen that p is or is equivalent to a unique number, while & p is a unique layer, which belongs to the second unique, point to 1 unique element int *** p3 = & p2; obviously, the second unique pointer obtains the three unique pointers .... pointing to the binary element ...... the difference between an array name and a pointer is that the array name is a const pointer and cannot assign values to the pointer itself. Cannot it change the pointer itself? Is there a difference between the two? No, so, for int a [4]; a is a unique pointer (constant), and a is of course the only pointer type.

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.