C and pointer-multi-dimensional array

Source: Internet
Author: User
# Include <stdio. h> int main (void) {int A [2] [3]; printf ("% P \ n", a); printf ("% d \ n ", sizeof (a); printf ("% P \ n", A + 1); printf ("% d \ n", sizeof (a + 1 )); printf ("% P \ n", * (a + 1); printf ("% d \ n", sizeof (* (a + 1 ))); return 0 ;}

The aboveCodeThe execution result is:
0xbfc094b8
24
0xbfc094c4
4
0xbfc094c4
12

A is a constant pointer. sizeof (a) obtains the size of the entire array, 2*3*4 = 24 bytes.
A + 1 is a "pointer to an array containing three integer elements", so sizeof (a + 1) only obtains the size of a normal integer pointer. In my system, it is 4 bytes.
* (A + 1) identifies a sub-array containing three integer elements. Its type is "pointer to an integer", which is a constant pointer, similar to, but the element in array a is int [3], and * (a + 1) points to the array element is int. The result is 3*4 = 12 bytes.

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.