C language arrays, pointer arrays, array pointers, two-dimensional array pointers

Source: Internet
Author: User

1. Arrays and pointers

int array[5] = {1,2,3,4,5}; // Defining Arrays
   1. Pointer and array relationships
int * pa = array;
  pa = array; // p[0] = = * (p+0) = = Array[0] = = * (array+0) printf ("%p\n", PA); printf ("%p\n", array); /* Access An array of two ways 1. The subscript method accesses the array name [subscript] pointer [subscript] subscript: Offset 2. Pointer method Access * (p+1) */

2. Array of pointers

 int  array[5 ] = {1 , 2 , 3 , 4 , 5 }; //     defines an array  int  (*p) [5 ] = &array; //     Defines an array pointer  int  *arr[5 ]; //  pointer array, so the element in the array retains the position of the int pointer 

    *p = p[0];    (*p) [1]  = = array[1];    p[0] [1]  = = (*p) [1] = = array[1];

3. Two-D array pointers

    //pointers to 32-D arrays    intarray2[2][3] = {{1,2,3},{4,5,6}}; int(*P2) [2][3]  =NULL; P2 = &array2;//assigns the array pointer to the array*p = =array2; (*P) [0][0] = = p[0][0][0]; //    /**    //p + 1 crosses 6 * 4 bytes//P[0] + 1 crosses 3 * 4 bytes//P[0][0] + 1 crosses 4 bytes//P[0][0][0] + 12-d array first element value +1//    */

4. Array of pointers

The elements in the array are pointers (addresses)

    int *arr[5]; // array of pointers, so the elements in the array retain the position        of the int pointer int 1 ;        arr[1] = &a;

5. Pointer to pointers

    // 4. Two-D pointer    int A;     int *p = &A;     int **pp = Pointer to &p;//pointer

C language arrays, pointer arrays, array pointers, two-dimensional array 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.