convert array to two dimensional array by pointer

后端 未结 5 900
无人及你
无人及你 2020-12-17 02:22

Is it possible to convert a single dimensional array into a two dimensional array?

i first tought that will be very easy, just set the pointer of the 2D array to the

5条回答
  •  被撕碎了的回忆
    2020-12-17 02:48

    You can't initialise an int bla[2][3] with an int* (what foo becomes in that context).

    You can achieve that effect by declaring a pointer to arrays of int,

    int (*bla)[3] = (int (*)[3])&foo[0];
    

    but be sure that the dimensions actually match, or havoc will ensue.

提交回复
热议问题