Why would İ prefer to use a variable rather than a constant? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why would İ prefer to use a variable rather than a constant?

29th Dec 2015, 6:25 PM
Kevin Kiambe
Kevin  Kiambe - avatar
6 Answers
+ 3
A constant is generally used in a program wherein you don't want to change its value throughout the execution of the main program, or by any of external functions accidentally, as in some cases. It gives advantage as in whenever a part of code tries to change its value, it reports an error.
29th Apr 2016, 11:32 AM
Kaustubh Dave
Kaustubh Dave - avatar
+ 1
i.e. pi number, it never changes so it should be a constant
11th Jun 2016, 9:03 AM
Ivan Nieto
Ivan Nieto - avatar
+ 1
an other advantage is that this "variables" are located in program memory and not in ram memory
18th Jun 2016, 1:46 AM
Alejo R Minetti
Alejo R Minetti - avatar
0
I think it's because you can't change a const value after initializing
28th Mar 2016, 4:47 AM
topemide
topemide - avatar
0
when you set it as a constant, there's less chances that another part of your program alters it's value... so it reduces the chances of getting errors...
14th Jun 2016, 5:11 PM
ryanc++
ryanc++ - avatar
0
Would you ever need a constant in a game?
27th Jun 2016, 5:22 AM
ethan
ethan - avatar