When we want to have a read-only object or promise not to change the value of some object in the current scope, we make it a constant. C++ uses the
const type qualifier to mark the object as a read-only. We say that our object is now
immutable. To define an integer
constant with a value of five, for example, we would write
int main()
{
const int n = 5;
}
We can now use that constant in places such as an array size:
int main()
{
const int n = 5;
int arr[n] = { 10, 20, 30, 40, 50 };
}
Constants are not modifiable. ...