在C语言中,数组名表示的实际上是数组首元素的地址。地址不是变量,是不能被赋值的。
下面几种写法都是合法的:
char s[10] = "student"; //初始化时的语法糖
char s[10] = {'s', 't', 'u', 'd', 'e', 'n', 't'}; //按元素赋值
char s[10]; strcpy(s, "student"); //字符串拷贝
char s[10]; s[0] = 's'; //数组元素赋值
char s[10], *p; p = s; p = "student"; //数组s的内容不会被改变,只是指针p改变