C compound literals, pointer to arrays

前端 未结 5 1838
南笙
南笙 2020-12-13 13:12

I\'m trying to assign a compound literal to a variable, but it seems not to work, see:

  int *p[] = (int *[]) {{1,2,3},{4,5,6}};

I got a er

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 14:13

    The one that you are using is array of int pointers. You should use pointer to array :

    int (*p)[] = (int *) {{1,2,3}, {4,5,6}}
    

    Look at this answer for more details.

提交回复
热议问题