gpt4 book ai didi

c - 为什么下面会产生segmentation fault呢?

转载 作者:太空狗 更新时间:2023-10-29 17:02:13 25 4
gpt4 key购买 nike

int main()
{
char *temp = "Paras";

int i;
i=0;

temp[3]='F';

for (i =0 ; i < 5 ; i++ )
printf("%c\n", temp[i]);

return 0;
}

为什么 temp[3]='F'; 会导致段错误,因为 temp 不是 const

最佳答案

不允许修改字符串文字。

关于c - 为什么下面会产生segmentation fault呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4231024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com