0% found this document useful (0 votes)
5 views2 pages

Declaring Constants in C: const vs #define

The document explains how to declare variables as constants using the 'const' keyword in programming. It includes examples demonstrating the declaration of constant variables and the output of sample programs. Additionally, it discusses the use of the #define preprocessor directive for declaring constants.

Uploaded by

Mukilesh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Declaring Constants in C: const vs #define

The document explains how to declare variables as constants using the 'const' keyword in programming. It includes examples demonstrating the declaration of constant variables and the output of sample programs. Additionally, it discusses the use of the #define preprocessor directive for declaring constants.

Uploaded by

Mukilesh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Vari

abl
escanbedeclaredasconst
antusi
ngtheconstkey
wor
dort
he#def
inepr
epr
ocessor
di
rect
[Link]
ail
saboutthesear
egi
venasfol
l
ows.

Theconstkey
wor
d

Vari
abl
escanbedeclar
edasconstant
sbyusingthe“const
”key
wordbef
orethedat
aty
peoft
he
var
iabl
[Link]
antvar
iabl
escanbeini
ti
ali
zedonceonly
.Thedef
aul
tval
ueofconst
ant
var
iabl
esarezer
o.

Aprogr
am t
hatdemonst
rat
est
hedecl
arat
ionofconst
antv
ari
abl
esi
nCusi
ngconstkey
wor
dis
gi
venasfol
l
ows.

Exampl
e

Li
veDemo

#i
ncl
ude<st
dio.
h>

i
ntmai
n(){

consti
nta;

consti
ntb=12;

pr
int
f("
Thedef
aul
tval
ueofv
ari
abl
ea:
%d"
,a)
;

pr
int
f("
\nThev
alueofv
ari
abl
eb:
%d"
,b)
;

r
etur
n0;

Theout
putoft
heabov
epr
ogr
am i
sasf
oll
ows.

Thedef
aul
tval
ueofv
ari
abl
ea:
0

Thev
alueofv
ari
abl
eb:
12

The#def
inepr
epr
ocessordi
rect
ive
Vari
ablescanbedecl
aredasconst
ant
sbyusi
ngt
he#def
inepr
epr
ocessordi
rect
iveasi
t
decl
aresanali
asforanyval
ue.

Aprogram t
hatdemonstrat
esthedeclar
ati
onofconst
antv
ari
abl
esi
nCusi
ng#def
ine
pr
eprocessordi
rect
ivei
sgivenasfol
lows.

Exampl
e

Li
veDemo

#i
ncl
ude<st
dio.
h>

#def
inenum 25

i
ntmai
n(){

pr
int
f("
Thev
alueofnum i
s:%d"
,num)
;

r
etur
n0;

Out
put

Theout
putoft
heabov
epr
ogr
am i
sasf
oll
ows.

Thev
alueofnum i
s:25

You might also like