Constant generally known as “const” keyword in programming language. It can assign a constant value in a variable.
const data_type variable_name=value;
Look at the program given below:



If you assign a new value in a variable, it will erase the old value and save the new value. You can change variable value as many as you want. But if you want to prevent to modify the value, you should use const keyword. If you use const keyword, you can’t change the value of a variable. For example:

This program will show an error massage. Because you have used const keyword and changed the value of ‘a’ in fifth line of the program.
[Note: you must initialize const variable during declaration.]

Next Previous