Saturday, June 27, 2009

Multi-dimensional arrays

#include
#include
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 for instance:
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
Expanation :
a[i][j] = a[i]+j and so on apply the rule

0 comments:

Post a Comment