I am new to C++ and just started learning pointers. If I write the code -
const int n = 4;
int m = 4;
const int *p = &n;
I understood this much that const makes the variable unchangeable. So if I want to change n, I cannot, but what value is the pointer having that is unchangeable? Because the next code is executing propery -
p = &m;
Shouldn't this give an error since it was already storing the value of n in the first place? I am sorry if it is a dumb question.
const int *p = &n;you can change the address, but you cannot change the value. So,*p = 8;will give you error.