2011年1月8日 星期六

Multiple Dimension Array

#include <stdio.h>

int main()
{
    int a[3][4] = {{1,2,3,4},{9,10,11,12},{13,14,15,16}};
    printf("%d\n", a[0][0]);
    printf("%d\n", a[2][3]);
    printf("%d\n", *(*(a+2)+3));
    printf("%d\n", *(*a + 2*4 + 3));
}
Output: 1 16 16 16
Note: for int a[m][n], we can use *(*(a+x) + y) and *(*a + x*m + y) to access a[x][y]. In both methods, we need to dereference twice.

沒有留言:

張貼留言