Two dimensional arrays and pointers

后端 未结 4 1315
春和景丽
春和景丽 2021-01-18 04:23

I have the following code snippet:

char board[3][3] = {
                     {\'1\',\'2\',\'3\'},
                     {\'4\',\'5\',\'6\'},
                          


        
4条回答
  •  死守一世寂寞
    2021-01-18 04:46

    Of course this will print the same address.
    Think about 2D arrays like this for a minute,

    int **ptr;


    The address *ptr does equal &(**ptr).

    Because basically, that's what your code is doing.

    and remember that in memory, 2D arrays will be mapped linearly.

提交回复
热议问题