C-language pointer arrays and arrays pointers

Source: Internet
Author: User

Declares an array pointer:

This is a pointer to an array of integers of length 4

Declare an array of pointers:

int *p2[4];//pointer array

This is an array that contains 4 pointers to integers

  

Start P1 point to the first row of the array, and now point to the second row

The results are as follows:

  

  

P2[0] = (int*) A;

P2[0] is an integer pointer that now points to the first element of the two-dimensional array a

  

The complete code is as follows:

#include <cstdio>int main () {int a[2][4] = {1,2,3,4,5,6,7,8};//int (*P3) [4][5];//This is also an array pointer int (*P1) [4];//pointer to an array] int *p2[4];//pointer array int *p4 = (int*) a;p1 = a;p2[0] = (int*) a;p1++;//equivalent to p4+4, 4 units of printf were moved backwards ("%d%d%d%d \ n", (*P1) [0], ( *P1) [1], (*P1) [2], (*P1) [3]);//Print 5, 6, 7, 8 printf ("%d%d%d%d \ n", P2[0][0], p2[0][1], p2[0][2], p2[0][3]);//print 1, 2, 3 , 4 return 0;}

Run results

  

C-language pointer arrays and arrays pointers

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.