c语言字符串赋值#include stdio.hint main () { char s[10]; s='字符串'; //main.c :14336073360 error : assignmenttoexpressionwitharraytype//s=' string '; char *sp; * sp='字符串'; //segmentationfaultchar * SPI=' string!' ; //Success} char s[10];
s='字符串'; //main.c :14336073360 error : assignmenttoexpressionwitharraytype
之所以发生assignmenttoexpressionwitharraytype错误,是因为s是数组名称,无法为数组名称赋值。
char *sp;
* sp='字符串'; //Segmentation fault
为什么会出现segmentation fault? sp是指针类型,指向字符,因此无法存储字符串