首页 > 编程知识 正文

C语言如何赋值,c语言赋值规则

时间:2023-05-04 18:23:54 阅读:21199 作者:4064

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是指针类型,指向字符,因此无法存储字符串

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。