·  C – Syntax – Pointers – To Array

 

- Info:

  - Pointer to Array is Pointer that holds address at which some Array is stored.

  - Adding 1 to pointer will increas its value by the size of the array.

 

- Examples:

  - Create C Console Application Test.c.

 

    Test.c

    #include <stdio.h>

   

    int main () {

   

      int       a[4] = {10,11,12,13};

      int  (*pta)[4] = &a;          /* (*pta) and (pta[0]) behave complitely the same as (a). */

   

      /* ARRAY. ----------------------------------------------------------------- */

      printf("%i\n",    (a)      ); /* 2293600 Array. Array address is displayed. */

      printf("%i\n",   &(a)      ); /* 2293600 Array address.                     */

      printf("%i\n",  *&(a)      ); /* 2293600 Array. Array address is displayed. */

      printf("%i\n", &*&(a)      ); /* 2293600 Array address.                     */

   

      /* POINTER TO ARRAY. ------------------------------------------------------ */

      printf("\n");

      printf("%i\n",    (*pta)   ); /* 2293600 Array. Array address is displayed. */

      printf("%i\n",   &(*pta)   ); /* 2293600 Array address.                     */

      printf("%i\n",  *&(*pta)   ); /* 2293600 Array. Array address is displayed. */

      printf("%i\n", &*&(*pta)   ); /* 2293600 Array address.                     */

   

      printf("\n");

      printf("%i\n",    (pta[0]) ); /* 2293600 Array. Array address is displayed. */

      printf("%i\n",   &(pta[0]) ); /* 2293600 Array address.                     */

      printf("%i\n",  *&(pta[0]) ); /* 2293600 Array. Array address is displayed. */

      printf("%i\n", &*&(pta[0]) ); /* 2293600 Array address.                     */

   

    }

 

    Test.c

    #include <stdio.h>

   

    int main () {

   

      int       a[4] = {10,11,12,13};

      int  (*pta)[4] = &a;           /* (*pta) and (pta[0]) behave complitely the same as (a). */

   

      /* ARRAY. ------------------------------------------------------------------ */

      printf("%i\n",  (a[0])      ); /* 10      Variable.                          */

      printf("%i\n", &(a[0])      ); /* 2293600 Variable address.                  */

   

      /* POINTER TO ARRAY. ------------------------------------------------------- */

      printf("\n");

      printf("%i\n",  (*pta)[0]   ); /* 10      Variable.                          */

      printf("%i\n", &(*pta)[0]   ); /* 2293600 Variable address.                  */

   

      printf("\n");       

      printf("%i\n",  (pta[0])[0] ); /* 10      .                                  */

      printf("%i\n", &(pta[0])[0] ); /* 2293600 Variable address.                  */

   

    }

 

    Test.c

    #include <stdio.h>

   

    int main () {

   

      int    a[2][4] = { {10,11,12,13},

                         {20,21,22,23} };

   

      int  (*pta)[4] = &a[0];          /* (*pta) and (pta[0]) behave complitely the same as (a). */

   

      /* ARRAY. -------------------------------------------------------------------- */

      printf("%i\n",  (a[1][0])     ); /* 20      Variable.                          */

      printf("%i\n", &(a[1][0])     ); /* 2293616 Variable address.                  */

   

      /* POINTER TO ARRAY. --------------------------------------------------------- */

      printf("\n");

      printf("%i\n",  (*(pta+1))[0] ); /* 20      Variable.                          */

      printf("%i\n", &(*(pta+1))[0] ); /* 2293616 Variable address.                  */

   

      printf("\n");

      printf("%i\n",  (pta[1])[0]   ); /* 20      Variable.                          */

      printf("%i\n", &(pta[1])[0]   ); /* 2293616 Variable address.                  */

   

    }