Created
May 27, 2011 19:15
-
-
Save davestevens/995937 to your computer and use it in GitHub Desktop.
3 Dimensional static array with pointer access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define ONE 5 | |
#define TWO 2 | |
#define THREE 3 | |
typedef struct { | |
unsigned int temp; | |
} rah; | |
typedef rah Array[ONE][TWO][THREE]; | |
void test(rah arr[][TWO][THREE]); | |
int main(void) { | |
Array array; | |
int i, j, k; | |
printf("%p\n", (void *)array); | |
for(i=0;i<ONE;i++) | |
for(j=0;j<TWO;j++) | |
for(k=0;k<THREE;k++) { | |
array[i][j][k].temp = j+k; | |
printf("[%d][%d][%d] = %d (%p)\n", i, j, k, array[i][j][k].temp, (void *)(&array[i][j][k].temp)); | |
} | |
test(array); | |
return 0; | |
} | |
void test(rah arr[][TWO][THREE]) { | |
int i, j, k; | |
for(i=0;i<ONE;i++) | |
for(j=0;j<TWO;j++) | |
for(k=0;k<THREE;k++) | |
printf("[%d][%d][%d] = %d (%p)\n", i, j, k, arr[i][j][k].temp, (void *)&arr[i][j][k].temp); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment