What's the point of const pointers?

后端 未结 17 1930
粉色の甜心
粉色の甜心 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:56

    Passing a const pointer to a function makes little sense, as it will be passed by value anyways. It's just one of those things that are allowed by the general language design. Prohibiting it just because it doesn't make sense would just make the language spec. larger.

    If you are inside a function it is of course another case. Having a pointer that cannot change what it points to is an assertion that makes the code clearer.

提交回复
热议问题