This is what I have:
const int x = 10;
int *ptr = &x; //error: 'initializing': cannot convert from 'const int *' to 'int *'
I know x
can't be modified after initializing and I know how to fix this compilation problem, but why can't I use a pointer (in this case ptr
) to point to x
?
Although it is a const int
, I don't understand the reason behind of why can't I point to it, as I can still use *ptr
to represent x
, right?