When to Use const vs constexpr in C++

While introducing myself to Modern C++ & its new features introduced in C++11 & C++14, I have completely neglected this keyword constexpr. Initially, I was confused about when to use const vs constexpr in C++ & how this constexpr works & differ with const. So, I have studied this from different sources & here is the consolidation of it: Primitive constexpr Variables 1 2 3 int varA = 3; const int varB = 5; constexpr int varC = 7; All of the above variable having a value which is known at compile time....

September 12, 2019 · 5 min · 935 words · Vishal Chovatiya