C/C++ Char Pointer Crash

前端 未结 7 481
甜味超标
甜味超标 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:07

    It's not the brackets, but the assignement. Your function returns not a simple char *, but const char *( i can be wrong here, but the memory is read-only here), so you try to change the unchangeable memory. And the brackets - they just give you access to the element of the array.

提交回复
热议问题