Page Stats
Visitor: 658
Constant Variable
Constant variables are those variables whose value cannot be changed during the execution of a program. Constant variable can be declared as local and global variable. Constant variable is declared with the keyword const.
Constant Variable Rule: Value of constant variable is assigned at the time of declaration only.
Syntax: const int i = 5; const float f = 5.5; const char ch = 'a'; const a = 5; //can be declare as without data type.
Note: If data type is omit, in that case default data type is assigned that is int.
Example 1: Constant Variable declaration.
void main() { const int a=10; clrscr(); printf("Value of a = %d\n",a); //a=20;//error, value of constant variable cannot be changed getch(); }
Value of a = 10