使用指针符号初始化数组
Initializing an array using pointer notation
是否可以使用来自另一个数组的指针符号来初始化一个数组?
澄清一下,如果可以使用 sizeof(*table) 来 return 行的大小,为什么分配特定行的行不起作用 table ?有什么方法可以使用 double table2[3] = *table;仅将 table 的第一行分配给 table2.
#include <stdio.h>
int main()
{
double table[2][3] = {{1.1, 1.2, 1.3},{2.1, 2.2, 2.3}};
double table2[2][3]=table;
// initial variant was double table2[3]=*table;
}
Is it possible to initialize an array using pointer notation from another array?
不,不是。标准规定
[...] the initializer for an object that has aggregate or union type shall be a brace-enclosed list of initializers for the elements or named members.
(C2011, 6.7.9/16)
此外,请注意,这样的初始化器 不是 数组文字(它们的形式略有不同,并且不允许作为数组初始化器),并且尽管数组和指针有着密切的联系,它们是完全不同的东西。您不能在任何地方将指针(或其他任何东西)分配给整个数组。
是否可以使用来自另一个数组的指针符号来初始化一个数组?
澄清一下,如果可以使用 sizeof(*table) 来 return 行的大小,为什么分配特定行的行不起作用 table ?有什么方法可以使用 double table2[3] = *table;仅将 table 的第一行分配给 table2.
#include <stdio.h>
int main()
{
double table[2][3] = {{1.1, 1.2, 1.3},{2.1, 2.2, 2.3}};
double table2[2][3]=table;
// initial variant was double table2[3]=*table;
}
Is it possible to initialize an array using pointer notation from another array?
不,不是。标准规定
[...] the initializer for an object that has aggregate or union type shall be a brace-enclosed list of initializers for the elements or named members.
(C2011, 6.7.9/16)
此外,请注意,这样的初始化器 不是 数组文字(它们的形式略有不同,并且不允许作为数组初始化器),并且尽管数组和指针有着密切的联系,它们是完全不同的东西。您不能在任何地方将指针(或其他任何东西)分配给整个数组。