相关疑难解决方法(0)

为什么可以将char char*分配给char*?

我知道例如"hello"是类型const char*.所以我的问题是:

  1. 我们如何分配像"hello"这样的非字符串const char*:

    char* s = "hello";  // "hello" is type of const char* and s is char*
                        // and we know that conversion from const char* to
                        // char* is invalid
    
    Run Code Online (Sandbox Code Playgroud)
  2. 是一个文字字符串"hello",它将在我的所有程序中占用内存,或者就像临时变量在语句结束时会被销毁?

c++ string char literals

15
推荐指数
1
解决办法
5723
查看次数

标签 统计

c++ ×1

char ×1

literals ×1

string ×1