# Pointer to Three-Dimensional Arrays in C

by Dinesh Thakur Category: Function and Pointer

If elements of an array are two-dimensional arrays, the array is called a three-dimensional array. Therefore, a three-dimensional array may be considered as an array of matrices. Let Arm be a 3-dimensional array or an array of matrices. The declaration of pointer and its initialization is carried out as given below.

int Arm   ;

int (*pArm)   = Arm ;

In the above declaration, pArm is the pointer identifier and Arm is the address of the three-dimensional array int Arm   . Therefore, pArm = Arm, because both are pointers to the first element of the array. The elements of the array may be accessed either through index values or through pointers using offset values. Thus, an element of an array with index values i,j, and k may be accessed through the [ ] operator by the following expression:

Arm[i] [j] [k]

The elements may also be accessed by the following expressions in pointer notation. In these expressions, the values of offsets i,j, k are same as the index values. The array name Arm is a constant pointer to the array.

*(*(*(Arm +i) + j) + k)

The elements may also be accessed by the pointer pArm as declared above.

*(*(*(pArm +i) + j) + k)

Program pointer to a three-dimensional array and its output.

```#include <stdio.h>int main (){   int A   = {{1,2,3,4 ,10,11,12,13, 20,21,22,23}, { 30,31,32,33, 40,41,42,43, 50, 51, 52,53 }} ;   int(*pA)   =A ;   int i, j, k;   for ( i =0; i<2; i++)     {          printf("The elements of A[%d] [j] [k] are given below.\n", i);         for ( j =0; j <3; j++)             {                  for ( k =0; k<4; k++)                      printf("%d\t", *(*(*(pA +i) + j) +k));                      printf ("\n");              }       }            printf ("\n");            return 0; } ``` Dinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles