In the code snippet that you have written u r changing the value of the
variable d which has been defined as auto variable (int d)

Now when u declare
const int *const ptr = &d;

that means both the ptr and int are constant and u cant change either so u
cant deference ptr to some other int value

hence it doesnt work

try doing

const int d=1 ;

This would give error saying

 error: assignment of read-only variable `d'

I hope this make things clear

Regards
Ankur

On Mon, Aug 8, 2011 at 10:23 AM, mohit verma <[email protected]> wrote:

> In c++
>
> int d=1;
> const int *const ptr = &d;   means ptr is const ptr to const object .So
> neither ptr nor d can be changed. But
>
> when i do -
>  d=5;
> cout<<d<<" "<<*ptr;
> the values are changed. Why is it so?
> Moreover doing something like : *ptr=5 gives error. Can someone explain
> internals here?
> --
> ........................
> *MOHIT VERMA*
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to