我有一个包含字符串值的 struct :
struct Demo {
char str[256];
};
当我try 初始化 struct 时,如下所示:
char str[256] = "asdasdasd";
struct Demo demo = {str};
// print to check what's in there
puts(demo.str);
我收到了一个警告:
warning: initialization of ‘char’ from ‘char *’ makes integer from pointer without a cast [-Wint-conversion]
8 | struct Demo demo = {str};
| ^~~
.\Untitled-1.c:8:29: note: (near initialization for ‘demo.str[0]’)
为什么当 struct 需要包含字符串时,字符demo.str[0]
会被初始化?