Constants In C Language
If you want to define a
variable whose value cannot change, you can use the const keyword. This will create a constant.
Fig: Constant In c |
For Example
Const double PI=3.14;
We have added keyword const.
And here,
PI is a symbolic constant; its values cannot be changed.
Const double PI=3.14;
PI=2.9; //Error
Program of Constant
#include<stdio.h>
int main()
{
Const float PI=3.14;
PI=3.4;
Printf(“the value of PI
is %f”,PI);
return 0;
}
Output:
Compile time error:
cannot modify const object.
No comments:
Post a Comment