How to assign multiple values at once to multi-dimensional array AFTER creating it - in C?

﹥>﹥吖頭↗ 提交于 2019-12-06 09:44:11

Since an array is not a modifiable lvalue, it cannot appear on the left side of an assignment. You can initialize it and you can assign individual members via indexing.

6.3.2.1

A modifiable lvalue is an lvalue that does not have array type, does not have ...

And a modifiable lvalue:

The name ‘‘lvalue’’ comes originally from the assignment expression E1 = E2, in which the left operand E1 is required to be a (modifiable) lvalue.

So no, you can't do what you want.

memcpy from another one will overwrite what is already in ary.

int ary[4][4];
int another[4][4] = {{1,2,3,4}, {5,6,7,8}, {1,2,3,4}, {5,6,7,8}};
memcpy(ary, another, 4 * 4 * sizeof(int));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!