+ 2
What's the difference between const and constexpr?
where they use? how they use?
4 Respostas
+ 10
'const' declares that an identifier used as a variable is a constant, the value held by that variable cannot be changed.
'constexpr' declares that the value of a variable/function can be determined during compile time, and said variable/function can appear within constant expressions.
https://stackoverflow.com/questions/4748083/when-should-you-use-constexpr-capability-in-c11
http://en.cppreference.com/w/cpp/language/constexpr
+ 10
You *can* replace const with constexpr, but note that they are not identical. This is similar to a case of using long int over int - You can store values with long int, including and beyond what int is capable of storing, but we don't replace one with another because it doesn't necessarily reflect what we want to do.
https://stackoverflow.com/questions/15078689/should-i-always-replace-const-int-with-constexpr-int-in-c11-whenever-possi
+ 2
@Hatsy Rei is that mean constexpr have include all the feature that const have, but const didn't. means we can replace const with constexpr?
+ 1
@Hatsy Rei tq for your informative and detailed answer 😊😊