Initializing a pointer to compound literals in C

喜欢而已 提交于 2019-12-06 16:18:53

Yes, it is valid to have a pointer to compound literals. Standard allows this.

n1570-§6.5.2.5 (p8):

EXAMPLE 1 The file scope definition

int *p = (int []){2, 4};

initializes p to point to the first element of an array of two ints, the first having the value two and the second, four. The expressions in this compound literal are required to be constant. The unnamed object has static storage duration.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!