I
I
Ivan Ivanov2014-01-20 20:19:13
C++ / C#
Ivan Ivanov, 2014-01-20 20:19:13

Is it necessary to attribute const if you put a suffix?

For example, what is the difference:
const float var1 = 324.1;from the float var1 = 324.1Fsuffix F does it already mean that it is a constant?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fat Lorrie, 2014-01-21
@Csklassami

A constant is the literal itself (with a suffix). And to a variable you appropriate (in this case - you copy) value of a constant. It looks like this situation:

const int c = 35;
int var = c;

var contains the value copied from the constant. But we can change var? As for the const
modifier itself , it is better to write it wherever possible.

J
jcmvbkbc, 2014-01-20
@jcmvbkbc

const refers to float var1, not the value it is initialized with. If you want to be able to change the value of var1 later on, const is not needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question