C++ Constants

Constants

When you do not want others (or yourself) to change existing variable values, use the const keyword (this will declare the variable as “constant”, which means unchangeable and read-only):

Example

const int myNum = 15;  // myNum will always be 15
myNum = 10;  // error: assignment of read-only variable 'myNum'

You should always declare the variable as constant when you have values that are unlikely to change: Continue reading C++ Constants

C Constants

Constants

If you don’t want others (or yourself) to change existing variable values, you can use the const keyword.

This will declare the variable as “constant”, which means unchangeable and read-only: Continue reading C Constants