I am learning const pointers and values, I get however a problem with assignment ptr2 = &x, error C2440: '=' : cannot convert from 'const int *' to 'int *'. Why? ptr2 is not constant so i can change address it's pointing to, x is const but I don't change its value. I am confused.
const int x = 10;
int y = 20;
int * const ptr1 = &y; // const pointer must be initialized
int *ptr2 = &y;
cout << *ptr1 << endl;
*ptr1 = 5; // changes content of the address
cout << *ptr1 << endl;
ptr2 = &x; // changes address pointed to by ptr2, not content of x!
cout << *ptr2 << endl;