【发布时间】:2016-07-31 12:03:19
【问题描述】:
我正在尝试将多维数组分配给结构中的单元化数组,如下所示:
typedef struct TestStruct
{
int matrix[10][10];
} TestStruct;
TestStruct *Init(void)
{
TestStruct *test = malloc(sizeof(TestStruct));
test->matrix = {{1, 2, 3}, {4, 5, 6}};
return test;
}
我得到下一个错误:
test.c:14:17: error: expected expression before '{' token
test->matrix = {{1, 2, 3}, {4, 5, 6}};
C 中分配矩阵的最佳方法是什么?
【问题讨论】:
-
数组不能在 C 中赋值。它们可以被初始化,但这只能在定义时完成。
标签: c arrays memory-management