search
Login

Categories


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

3.8k questions

4k answers

117 comments

10.7k users

0 votes
3.2k views
asked Expert 13.2k points 26 40 57

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.

#include<stdio.h>

#include<string.h>

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;

}

Output:

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

Explanation:

This output may differ from computer to computer as the address locations are not same for every computer.
answered Guru 39.1k points 10 21 32

Related questions

0 votes
1 answer 114 views
0 votes
1 answer 635 views
635 views
An array of length n+1 is populated with integers in the range [1, n]. How to find a duplicate integer in linear time with O(1) space. The array is read-only and may not be modified.
asked baden Sr Member 2.4k points 6 10 17
0 votes
1 answer 42 views
42 views
asked rock Expert 15k points 15 23 29
0 votes
1 answer 43 views
0 votes
1 answer 29 views
...