const int a = 3;
const int *ptr_to_a = &a;
int *ptr;
ptr = (int*)ptr_to_a;
cout<<(*ptr_to_a)<<" "<<ptr_to_a<<endl;;
cout<<(a)<<" "<<&a<<endl;;
cout<<*ptr<<" "<<ptr<<endl;
// changing here.
(*ptr) = 5;
cout<<(*ptr_to_a)<<" "<<ptr_to_a<<endl;;
cout<<(a)<<" "<<&a<<endl;;
cout<<*ptr<<" "<<ptr<<endl;
Output is
3 0x7ffe87e48554
3 0x7ffe87e48554
3 0x7ffe87e48554
5 0x7ffe87e48554
3 0x7ffe87e48554
5 0x7ffe87e48554
Can anyone explain why its giving output 3 while at same location im getting value 5.