gpt4 book ai didi

c - 为什么字符串被声明为数组 "char word[5] = "hello"可修改,但字符串不能被声明为指针 (char *word = "hello")?

转载 作者:行者123 更新时间:2023-11-30 16:09:02 25 4
gpt4 key购买 nike

我的印象是

    char word[5] = "hello";

相同
    char *word = "hello"; 

因为数组总是衰减成指针?

最佳答案

char *word = "hello"; 获取字符串文字的地址。这些通常保存在只读存储器中。

关于c - 为什么字符串被声明为数组 "char word[5] = "hello"可修改,但字符串不能被声明为指针 (char *word = "hello")?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59221811/

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