Does declaring C++ variables const help or hurt performance?

后端 未结 5 1201
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 04:45

I understand the behavior of const-qualified data types. I am curious, though, if there is any performance gain or loss from over- or under-zealousness of quali

5条回答
  •  离开以前
    2020-12-19 05:17

    const is mainly a compile-time thing, however, declaring something as const sometimes allows for certain optimizations. If the code in question isn't a performance bottleneck, I wouldn't worry about it and just use const as intended: to produce clearer code and prevent yourself from doing stupid things.

提交回复
热议问题