C++ string literal data type storage

前端 未结 8 1077
一生所求
一生所求 2020-11-30 10:03
void f()
{
    char *c = \"Hello World!\"
}

Where is the string stored? What\'s the property of it? I just know it is a constant, what else? Can I

8条回答
  •  日久生厌
    2020-11-30 10:41

    it is packaged with your binary -- by packaged I mean hard-wired, so yes you can return it and use it elsewhere -- you won't be able to alter it though, and I strongly suggest you declare it as:

    const char * x = "hello world";
    

提交回复
热议问题