What's the point of const pointers?

后端 未结 17 1839
粉色の甜心
粉色の甜心 2020-11-30 17:28

I\'m not talking about pointers to const values, but const pointers themselves.

I\'m learning C and C++ beyond the very basic stuff and just until today I realized t

17条回答
  •  醉梦人生
    2020-11-30 17:58

    You're right, for the caller it makes absolutely no difference. But for the writer of the function it can be a safety net "okay, I need to make sure I don't make this point to the wrong thing". Not very useful but not useless either.

    It's basically the same as having an int const the_answer = 42 in your program.

提交回复
热议问题