const questions

Hi everyone,
short question- why does this implementation is illegal ?
if it was just integers it would work..
1
2
3
4
  	int a=6,b=4;
	const int*p=&a;
	int *r=&b;
	r=p;


thanks
Well I think the error is pretty much self explanatory: invalid conversion from const int* to int*.

The reson is that you declared a pointer to CONST integer. By assigning it to pointer to a NON-CONST integer, you could modify the value of what you previously wanted to remain unmodified :)
because int* != const int* , but const int* can be assign by int*
thanks ! helped me a lot to understand
Topic archived. No new replies allowed.