+ 2

wat is the use of const

3rd Jan 2017, 3:14 PM
vigneshwaran m
vigneshwaran m - avatar
4 Answers
+ 5
with the const keyword you can make a variable(,parameters etc...) value not changeble. this helps prevent accidental value changes and makes the code more self-explanatory.
3rd Jan 2017, 3:29 PM
DFX
DFX - avatar
+ 1
To ensure that the values of important data cannot be changed by the code.
7th Jan 2017, 11:22 AM
Diego
Diego - avatar
+ 1
for example you can define PI = 3.1415 and use it thorough your program.
28th Jan 2017, 5:33 PM
mohsen chavoshi
mohsen chavoshi - avatar
0
to prevent any change for the variable; further the use of const provides the compiler to do better optimations (e.g. replace with literals)
27th Jan 2017, 8:16 PM
nyx215
nyx215 - avatar