0
What is the difference between constants and variables
What is the difference between constants and variables
2 Answers
+ 6
Constants are defined in a way that you get an error when you try to change them in your code.
Like this, when the source gets longer and longer and it's hard to keep track of everything, you are able to protect the parts of your data that shouldn't ever change.
Variables can be changed whenever you want.
+ 3
From a mathematical point of view:
The difference between variables and constants is that variables can change their value at any time but constants can never change their value. (The constants value is locked for the duration of the program). Constants can be very useful, Pi for instance is a good example to declare as a constant.