use*_*215 6 c++ memory-management
在此示例中,在程序的生命周期中,字符串文字"hello"何时被分配和释放?
init(char **s)
{
*s = "hello";
}
int f()
{
char *s = 0;
init(&s);
printf("%s\n", s);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Mar*_*ork 15
字符串文字由编译器初始化为只读内存段.在运行时没有初始化或删除.