在C中,可以在声明中使用字符串文字,如下所示:
char s[] = "hello";
Run Code Online (Sandbox Code Playgroud)
或者像这样:
char *s = "hello";
Run Code Online (Sandbox Code Playgroud)
那么区别是什么呢?我想知道在编译和运行时的存储持续时间实际发生了什么.
例如,
int x[10];
int i = 0;
x = &i; //error occurs!
Run Code Online (Sandbox Code Playgroud)
根据C - A参考手册,数组名称不能是左值.因此,x不能是左值.但是,数组名称不能是左值的原因是什么?例如,为什么第三行发生错误?