What is the point of declaring a constant variable in C ++

Possible duplicate:
is const (C ++) optional?

In C ++ or any programming language, what is the declaration point of a const variable or constant? I understand what const does, but is it safer to declare everything not constant, because the programmer does not know whether to change the variable or not? I just don't see the purpose of const.

+3
source share
7 answers

If a programmer (or a development team) can successfully track every detail of each variable and not accidentally assign a value to a constant, then by all means declare constants const.

const , , .

, - FORTRAN 77. FORTRAN 77 , :

subroutine increment(i)
integer i

i = i + 1
end

subroutine process ()
call increment (1)
call someprocedure (1, 2, 3)
...

, someprocedure() (2, 2, 3)!

+5

, , ?

. "", , , , . , . , , ? .

, , ( ) , . , . , , .

, - , , , . , , , , .

+4

, ?

. . .

, , . const, . Const .

+1

, , , , , . , , , , , , ! .

, . , const, , . , . .

+1

const optmize code. const. , , const.

0

- , ( ) .

, , , .

0

, , ( ), .

, . , , , .

, , , , . , , , .

, , , , , - .

:)

0

All Articles