purpose of "const" when initializing and assigning a variable
what's the difference between
const int MAXVAL=10
and
int MAXVAL=10?
in both examples MAXVAL is assigned the integer value of 10 (?)
This is the difference:
1 2
|
// your line here, then do:
MAXVAL = 100;
| |
The
const modifier is used to make a variable non-volatile, meaning that its value cannot be changed.
1 2 3 4 5
|
const int constvar = 10;
int var = 1;
...
constvar = 20; // Compile-time error
var = 2;
| |
Last edited on
simple enough, thanks!
I wouldn't use that word, cause
volatile
means something entirely different again.
Topic archived. No new replies allowed.