我有一个问题,分配如下数组:
int a[];
int b[] = {1,2,3};
&a = &b;
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用指针,但我想这样试试......
在阅读了关于K&R书中结构的章节后,我决定做一些测试来更好地理解它们,所以我写了这段代码:
#include <stdio.h>
#include <string.h>
struct test func(char *c);
struct test
{
int i ;
int j ;
char x[20];
};
main(void)
{
char c[20];
struct {int i ; int j ; char x[20];} a = {5 , 7 , "someString"} , b;
c = func("Another string").x;
printf("%s\n" , c);
}
struct test func(char *c)
{
struct test temp;
strcpy(temp.x , c);
return temp;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:为什么c = func("Another string").x;工作(我知道这是非法的,但为什么它有效)?起初我用它写了strcpy()(因为这似乎是最合乎逻辑的事情)但我一直有这个错误:
structest.c: In function ‘main’:
structest.c:16:2: error: invalid …Run Code Online (Sandbox Code Playgroud)