Why do we use constexpr and const in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why do we use constexpr and const in c++

I don't understand the use of constexpr and const.why would we want to make a variable immutable?

12th Jun 2017, 1:33 PM
Asif
Asif - avatar
1 Answer
+ 4
It will enable the compiler to make optimizations in the code, making it faster. Const declarations tell the compiler that the variables are read-only.
12th Jun 2017, 2:04 PM
Karl T.
Karl T. - avatar