Developer community
0 votes
3.2k views
asked by Expert (13.2k points) 27 41 59 | 3.2k views

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 by Guru (39.1k points) 10 22 34

Related questions

0 votes
1 answer
0 votes
1 answer
asked by baden Sr Member (2.4k points) 6 10 17 | 638 views
0 votes
1 answer
asked by rock Expert (15k points) 15 23 31 | 52 views
0 votes
1 answer
0 votes
1 answer
asked by smith Geek (15.3k points) 17 41 61 | 31 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


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

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users