1.

Constants C

Answer»

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


Constant Value List

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


Constant Set Values
Output:-
The value of PI is: 3.140000


Another example which use to change contsant value


Constant Val Change
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


Constant Define Value
Output:-
3.140000


Discussion

No Comment Found