C/C++ Char Pointer Crash

前端 未结 7 447
甜味超标
甜味超标 2020-12-19 17:42

Let\'s say that a function which returns a fixed ‘random text’ string is written like

char *Function1()
{ 
return “Some text”;
}

then the p

7条回答
  •  隐瞒了意图╮
    2020-12-19 18:10

    Note also that you can avoid the crash by placing the text in a regular array:

    char Function1Str[] = "Some text";
    
    char *Function1()
    {
        return Function1Str;
    }
    

提交回复
热议问题