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:
Example
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:
Notes On Constants
When you declare a constant variable, it must be assigned with a value:
Example
Like this:
This however, will not work:
minutesPerHour = 60; // error
Good Practice
Another thing about constant variables, is that it is considered good practice to declare them with uppercase.
It is not required, but useful for code readability and common for C programmers: