const and constexpr
const values cannot change. constexpr is evaluated at compile time.
Example
#include <iostream>
constexpr int sq(int x) { return x * x; }
int main() {
const int a = 5;
constexpr int b = sq(4);
std::cout << a << " " << b << "\n";
return 0;
}Result
5 16
Exercise
Compile time constant.
int N = 5;Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.