char cString[10]="hello world" 是初始化,合法。

 

char cString[10];

cString="hello world" 是赋值,这样赋值非法。原因在于声明了cString数组后,cString其实是一个char型的常量指针,而cString="hello world" 一句的意思是将常量"hello world"的首地址赋给cString,这与cString指针的常量属性冲突。

可以用strcpy(cString, "hello world")的方法来赋值,但要注意检查cString空间是否足够

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
  • 2021-05-03
  • 2022-12-23
  • 2021-08-31
  • 2021-08-16
猜你喜欢
  • 2021-05-22
  • 2021-06-18
  • 2022-01-28
  • 2022-12-23
  • 2021-12-05
  • 2021-11-20
相关资源
相似解决方案