Is a string literal in c++ created in static memory?

前端 未结 4 2158
情书的邮戳
情书的邮戳 2020-11-22 15:07

Is a string literal in c++ created in static memory and destroyed only when the program exits?

4条回答
  •  梦谈多话
    2020-11-22 16:01

    Yes, string literals are valid for the entire duration of the program, even during the destruction of static objects.

    2.13.4/1 in the Standard says

    An ordinary string literal has type "array of n const char" and static storage duration.

    The Standard says of 'static storage duration' in 3.7.1/1:

    The storage for these objects shall last for the duration of the program.

提交回复
热议问题