Constant
Constant
2. Define the different types of Constant and give example for each type.
To declare a constant using const keyword, first is, we have to use the proper
syntax: const data_type var_name = value; . Next is to identify the data type (int,
float, char, string) and we just have to add the const keyword at the start of the
variable declaration. It is important to note that we have to initialize the
constant variable at declaration to prevent it from storing some garbage value as
we wouldn't be able to modify it afterwards.
a, b, c, and d are constant. Once their values are set to 21, 12.16, 'c', and
'lans' respectively, these values cannot be modified in the program.
#define A 21
#define B 12.16
#define C 'C'
#define HIM "I love you!"
In these examples, A, B, C, and HIM are constants. Their values are set to 21,
12.16, 'C', and "I love you!" respectively, and these values cannot be modified in
the program.
References:
Constant (computer programming). (2023, November 19). Wikipedia.
https://en.wikipedia.org/wiki/Constant_(computer_programming)