Constant
Constants are variables that do not change in the course of their use. When you declare and initialize a variable, you can specify a variable as a constant by adding a const to the front of the variable. Example: const int a=200;
Characteristics of constants:
Constants must be initialized at the time of declaration. Once you have specified its value, you can overwrite it.
The value of a constant must be used for calculations at compile time. Therefore, you cannot initialize a constant with a value that is extracted from a variable.
Constants are always static. You do not have to (in fact, not allow) a const declaration that contains modifier static.
There are at least 3 benefits to using constants in your program:
Easy to read, easy to modify and avoid mistakes.
Variable
An object that has variable names and values.
Declaration of variable: [access modifier] type variable name [= initial value]; Example: int i=0;
The variable name must be a letter or an underscore cannot have a special symbol at the beginning.
Note:
Variables must be initialized. Otherwise, the compiler has no basis for inferring the variable type.
The initializer cannot be empty.
The initializer must be placed in an expression.
The initializer cannot be set to an object unless a new object is created in the initialization.
Rookie note two, constants and variables