A const variable means that variable won't change. So `const int i = 6` means i will never change. But often you'll use pointers or references, these are C++'s way for a variable to point to data elsewhere. You can also make the pointers or references
themselves const. Finally, you can make functions const too, which lets you turn C++ into half a haskell.
First pointers and references. For simplicitly I'm going to ignore references and focus on pointers - the difference is not very interesting in this context. In most languages you probably know, referring to objects is done implicitly: variables that "are" objects are actually references to objects located elsewhere, and variables that are primitive types (numbers, booleans, strings) are just right there. Because of this, in JavaScript you can do this:
var a = {};
var b = a;
b.moo = 6;
a.moo === 6; // true
In here, a and b
point to some object that "is" neither a or b - the object itself just floats around in memory and it'll exist until neither a, b, nor anyone else points to it anymore and the GC decides it has to go.
In C++, you'll need pointers or references for this, eg.
somestruct a;
somestruct* b = &a; //b now points to a
a.moo = 6;
b->moo == 6; // true
(-> is just C++ shorthand for "follow the pointer and then do a property lookup).
Ok now const.
somestruct const a;
a.moo = 6; // error! can't modify a const.
Ok well how about
somestruct a;
somestruct* const b = &a;
b->moo = 6;
a.moo === 6; // true
This means the
pointer is const. That works because we never change
where b is pointing to. So how about:
somestruct a;
somestruct const* const b = &a;
b->moo = 6;
a.moo === 6; // true
Oh damn. Crying baby. Const functions will have to wait for some other day.