2013年11月21日 星期四

[觀點][C語言]multi array

#include <stdio.h>

int main()
{
    int sum = 0;
    int i, j;
    int ary[][4] = {1, 3, 5, 7, 9, 11};

    for (i = 0; i <=6; i++)
        for (j = 0; j <=6; j++)
        printf("ary[%d][%d] = %d\n", i, j, ary[i][j]);

    int (*ptr)[4] = ary;
    sum = (*ptr)[1] + ary [0][3] + ary[1][2];
    printf("sum = %d", sum);

    return 0;
}
[Answer]
ary[0][0] = 1
ary[0][1] = 3
ary[0][2] = 5
ary[0][3] = 7
ary[0][4] = 9
ary[0][5] = 11
ary[0][6] = 0
ary[1][0] = 9
ary[1][1] = 11
ary[1][2] = 0
ary[1][3] = 0
ary[1][4] = 15773951
ary[1][5] = 0
ary[1][6] = 4195824
ary[2][0] = 15773951
ary[2][1] = 0
ary[2][2] = 4195824
ary[2][3] = 0
ary[2][4] = 0
ary[2][5] = 5
ary[2][6] = 2
ary[3][0] = 0
ary[3][1] = 1
ary[3][2] = 3
ary[3][3] = 0
ary[3][4] = -2050383040
ary[3][5] = 32767
ary[3][6] = 0
ary[4][0] = -2050383040
ary[4][1] = 32767
ary[4][2] = 0
ary[4][3] = 0
ary[4][4] = 0
ary[4][5] = 0
ary[4][6] = -662104211
ary[5][0] = 0
ary[5][1] = 0
ary[5][2] = -662104211
ary[5][3] = 32702
ary[5][4] = 0
ary[5][5] = 0
ary[5][6] = -2050383032
ary[6][0] = 0
ary[6][1] = 0
ary[6][2] = -2050383032
ary[6][3] = 32767
ary[6][4] = 0
ary[6][5] = 1
ary[6][6] = 4195572
sum = 10

沒有留言:

張貼留言