Two-dimensional array pointer pointing to record, two-dimensional array pointer pointing

Source: Internet
Author: User

Two-dimensional array pointer pointing to record, two-dimensional array pointer pointing
Three rules:

(1) The array name is equivalent to a pointer to the first element of the array.

(2) & E is equivalent to raising the jurisdiction of E to a level

(3) * E is equivalent to lowering E's jurisdiction to a level.

Note:

(1) The priority of & and * is higher than that of + and-

(2) the output of the pointer to the array is the starting address of the array.

 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5     int a[3][4] = { {1,2,3,4},{5,6,7,8},{9,10,11,12} }; 6     cout << "a=" << a << endl; 7     cout << "&a[0]=" << &a[0] << endl << endl; 8  9     cout << "a+1=" << a + 1 << endl;10     cout << "&a[0]+1=" << &a[0] + 1 << endl << endl;11 12     cout << "a[1]=" << a[1] << endl;13     cout << "&a[1]=" << &a[1] << endl;14     cout << "*(a+1)=" << *(a + 1) << endl << endl;15 16     cout << "&a[0][0]+1=" << &a[0][0] + 1 << endl;17     cout << "*a+1=" << *a + 1 << endl << endl;18 19     cout << "&a=" << &a << endl;20     cout << "&a+1=" << &a + 1 << endl;21     return 0;22 }

Output result :(No. Is not in the output column, just for convenience of analysis)

1. a = 009efc6
2. & a [0] = 009efc6

3. a + 1 = 009EFC28
4. & a [0] + 1 = 009EFC28

5. a [1] = 009EFC28
6. & a [1] = 009EFC28
7. * (a + 1) = 009EFC28

8. & a [0] [0] + 1 = 009EFC1C
9. * a + 1 = 009EFC1C

10. & a = 009efc6
11. & a + 1 = 009EFC48

Result Analysis:

1. a points to the one-dimensional array a [0]

2. a [0] points to the first element of one-dimensional array a [0], and points to one-dimensional array a [0] With & Upgrade

 

3. a points to the one-dimensional array a [0], because the jurisdiction of one-dimensional array a [0] is a [0] [0], a [0] [1], a [0] [2], a [0] [3], + 1 points to the one-dimensional array a [1]

4. & a [0] points to one-dimensional array a [0], + 1 points to one-dimensional array a [1]

 

5. a [1] points to the first element a [1] of the one-dimensional array a [1] [0]

6. Use a [1] and point to array a [1] After Upgrade

7. a + 1 points to array a [1] and points to the first element a [1] [0] of the one-dimensional array after * downgrade.

 

8. & a [0] [0] points to a [0] [0], and + 1 points to a [0] [1]

9. * a points to the first element a [0] [0] of the one-dimensional array a [0], and + 1 points to the second element a [0] [1].

 

10. & a points to the two-dimensional array a [3] [4], and outputs its starting address during output.

11. & a's jurisdiction is a [0] [0]… A [2] [3], and then point to the address after the two-dimensional array a [3] [4]

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.