Difference between constexpr vs const

constexprconst
If a member function is declared as constexpr then it will be treated as const as well.If a member function is declared as const then it will not be treated as constexpr.
If a variable is declared as constexpr then it will be treated as const as well.If a variable is declared as const then it will not be treated as constexpr.
constexpr is mainly used for optimization purpose where computation can be done at compile level to optimize run time performance.However const is mainly used to ensure that there are no accidental changes done by the member method to member data.

For more information related to constexpr click here.

Leave a Reply

Your email address will not be published. Required fields are marked *