const int a = 3; 3 0x7ffe87e48554 Can anyone explain why its giving output 3 while at same location im getting value 5.
const int *ptr_to_a = &a;
int *ptr;
ptr = (int*)ptr_to_a;
cout<<(*ptr_to_a)<<" "<
// changing here.
(*ptr) = 5;
cout<<(*ptr_to_a)<<" "<
Output is
3 0x7ffe87e48554
3 0x7ffe87e48554
5 0x7ffe87e48554
3 0x7ffe87e48554
5 0x7ffe87e48554
Why it's giving output 3 while at same location I'm getting 5
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Rajanikant HawaldarRank #110 · 20.2K reputationPosted Jul 2, 2021, 2:21 AM EDT