C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers


10,705 users

What is the equivalent pointer expression for referring an element a[i][j][k][l], in a four dimensional array in C?

0 votes
asked Jan 8, 2014 by keem Expert (13,240 points)

1 Answer

0 votes
Consider a multidimensional array a[w][x][y][z].

In this array, a[i] gives address of a[i][0][0][0] and a[i]+j gives the address of a[i][j][0][0]

Similarly, a[i][j] gives address of a[i][j][0][0] and a[i][j]+k gives the address of a[i][j][k][0]

a[i][j][k] gives address of a[i][j][k][0] and a[i][j][k]+l gives address of a[i][j][k][l]

Hence a[i][j][k][l] can be accessed using pointers as *(a[i][j][k]+l)

where * stands for value at address and a[i][j][k]+l gives the address location of a[i][j][k][l].

Program: Example program to illustrate pointer denotation of multi-dimensional arrays.



int main() {

int a[3][3][3][3];

//it gives address of a[0][0][0][0] .

printf(" \n address of array a is %u", a);

printf("\n address of a[2][0][0][0] is %u ,given by a[2], %u given by a+2",

a[2], a + 2);

printf("\n address of a[2][2][0][0] is %u ,given by a[2][2], %u given by a[2]+2",

a[2][2], a[2] + 2);

printf("\n address of a[2][2][1][0] is %u ,given by a[2][2][1] , %u given by a[2][2]+1",

a[2][2][1], a[2][2] + 1);

return 0;



address of array a is 65340

address of a[2][0][0][0] is 65448, given by a[2] , 65448 given by a+2

address of a[2][2][0][0] is 65484, given by a[2][2] ,65484 given by a[2]+2

address of a[2][2][1][0] is 65490, given by a[2][2][1] , 65490 given by a[2][2]+1


This output may differ from computer to computer as the address locations are not same for every computer.
answered Jan 8, 2014 by rajesh Guru (39,140 points)

Related questions

0 votes
1 answer 109 views
0 votes
1 answer 627 views
627 views asked Oct 20, 2011 by baden Sr Member (2,360 points)
0 votes
1 answer 38 views
38 views asked Apr 8, 2014 by rock Expert (14,990 points)
0 votes
1 answer 40 views
0 votes
1 answer 27 views