我在问:是否可以在数组定义后执行多个赋值?我用不同的语法进行了不同的测试,但没有成功。
这是我的源代码:
#include <stdio.h>
typedef int coords[3];
int main(int argc, char **argv)
{
coords x = {1, 2, 3}; // it works
x = {1, 2, 3}; // it doesn't work. Compiler gives the 'error: expected expression before ‘{’ token'
// x = (int[3]) {1, 2, 3}; // it doesn't work. Compiler gives the 'error: assignment to expression with array type'
// x = (coords[3]) {1, 2, 3};// it doesn't work. Compiler gives the 'error: assignment to expression with array type'
// x = (coords) {1, 2, 3}; // it doesn't work. Compiler gives the 'error: assignment to expression with array type'
printf("%d\n", x[0]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我错在哪里?
谢谢
马可