ID:1936297
 
(See the best response by Ter13.)
Heya, so Imagine these 2 situations:

Situation A
var/Pi = 3.14


Situation B
var/const/Pi = 3.14


Pi is a cosntant value and so it should be defined as a const var (Situation B). This is logical, but couldn't I just define it as a normal variable, like in Situation A?

What is the difference between those 2 situations? Will those vars be handled differently by the computer?

I do understand that if I define a variable as constant I can't change its value but is that the only difference between a const var and a non const var?

Thanks as always,
,MistY
Best response
const values can't be changed, and when they belong to objects, aren't saved. That's the only difference.
Oh Thanks Ter.
IMO, you're better off using a #define for this--and of course using more digits of precision. Using #define means that any math that needs to be done with the value can be done at compile time. For instance, in x*PI/180, the fraction PI/180 can be done beforehand if you enclose it in parentheses. This reduces both the size of your code and the work done at runtime.