answersLogoWhite

0

A constant integer is an integer that is not expected to change value while it is in scope. Declaring any variable constant doesn't guarantee it won't change, but it does make it more difficult for a programmer to change the value by accident.

Constant integers must be initialised at the point of instantiation. We can initialise a constant with the value of a literal constant, the value of another constant, or the value of a variable:

void f (int v) {

const int x {42}; // Integer constant (initialised from literal constant)

const int y {x}; // Integer constant (initialised from another constant)

const int z {v}; // Integer constant (initialised from a variable)

// ...

v *= 2; // ok -- v is variable

x *= 2; // error: x is constant

}

User Avatar

Wiki User

8y ago

What else can I help you with?

Related Questions