Can/Why using char * instead of const char * in return type cause crashes?

后端 未结 5 1649
醉梦人生
醉梦人生 2021-01-05 15:12

I read somewhere that if you want a C/C++ function to return a character array (as opposed to std::string), you must return const char* rather than char*. Doing the latter m

5条回答
  •  [愿得一人]
    2021-01-05 15:17

    If the char* is allocated on the stack, you return a dangling pointer. Otherwise, so long as it matches the function's prototype and the declaration matches the return value, you should be fine.

提交回复
热议问题