| |
|
Constants C
Constants usually refer to fixed values that program may not be change during its execution. And these fixed value also called literals. And constants can be any of the basic data which types is either integer, floating or character constant. And constant value or variable that we cannot changed in the program. And value can be 50,100,"a",3.4 or "crackyourinterview.com" etc. There are different types of constants in C programming.
List of Constants in C
Different ways to define Constants in C
There are mainly 2 ways to define constant in C programming.
(1)const keyword
(2)#define preprocessor
(1)const keyword
The const keyword is used to define constant in C programming.
const float PI=3.14;
Now below example is the use of const variable PI
Output:-
The value of PI is: 3.140000
Another example which use to change contsant value
Output:-
Compile Time Error: Cannot modify a const object
(2)#define preprocessor
The #define preprocessor is also used to define constant.
Syntax:-
#define token value
Output:-
3.140000 | |
|
|
|
|