Pointer notation to declare a two dimensional array in C programming

116 views Asked by At

Given the following

0 1 2 3
4 5 6 7
8 9 10 11

How do I use pointer notation to declare the above data as a two dimensional array x.

Does it work to simply write

int (*x)[4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
1

There are 1 answers

0
TypeIA On
int x[4][4] = {
    {  0,  1,  2,  3 },
    {  4,  5,  6,  7 },
    {  8,  9, 10, 11 },
    { 12, 13, 14, 15 } };

printf("x[2][2] = %d\n", x[2][2]);