The relationship between the array name and its pointer in a two-dimensional array

Source: Internet
Author: User

Most beginners are not very clear about the existence of a two-dimensional array, today I would like to say that the two-dimensional array, computer memory is a series of storage units, we can interpret it as a line, yes, it is a line, then the problem, the two-dimensional is a what kind of existence??? Frankly speaking, the two-dimensional array is not really two-dimensional, but people are subjective to turn it into two-dimensional, for example! such as stairs, we all know that the staircase is a way to say plainly, but we deliberately move the staircase up and down the way, this is our subjective change, in fact we can be seen as a straight road, but the workers are bent. Okay, no, come on, go to the subject ....

The two-dimensional array name A is a pointer to the first row of the array, it points to an entire line, *a is the address of a[0][0], the array name A is an entire line address, *a is an element of the address, but at this time p=a, this p is a[0][0] address see the following program

1#include <stdio.h>2 3 intMain ()4 {5     inta[2][3]={1,2,3,4,5,6},*p;6     7p=A;8     9printf"%d%d%d\n", p,a,*a);Ten      One     return 0; A}

Results show

The address of the first line and the first element first address must be the same, we continue to see

1#include <stdio.h>2 3 intMain ()4 {5     inta[2][3]={1,2,3,4,5,6},*p;6     7p=A;8     9printf"%d%d\n", (p+1), * (A +1));Ten      One     return 0; A}

The results show that the address differences come out, the address of the No. 0 line is 6487600, so a[0][1] is 6487600, and the first row of the address is 6487612, is not a difference of 3 int byte, so this proves that a is the first line of the array of pointers, it points to a whole line, P is pointing to an element

Continue to prove

1#include <stdio.h>2 3 intMain ()4 {5     inta[2][3]={1,2,3,4,5,6},*p;6     7p=A;8     9printf"%d%d\n", * (p+1), * * (A +1));Ten      One     return 0; A}

Results

Conclusion: **a represents the address of the A[0][0],*a A[0][0], a represents the address of the first row

The relationship between the array name and its pointer in a two-dimensional array

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.