Question: I am little confused over the following situation

```
const char c = 'C';
char * p = const_cast<char *>(&c);

*p = 'K';
cout << " c = " << c << endl;
cout << " *p = " << *p << endl;

printf("c's address      : %u\n", &c);
printf("P is pointing to : %u\n", p);

```

Which outputs as below on execution

```
c = C
*p = K
c's address      : 3221180271
P is pointing to : 3221180271

```

Here I can observe that both '&c' and 'p' having the same address in the memory. 

Then what is the hidden mechanism by which 'p' is capable of storing a different value than 'c' is storing whereas both share the same address space in the memory?

Answer: 
```
const char c = 'C';
char * p = const_cast<char *>(&c);

*p = 'K';

```

This is undefined behaviour. If an object is originally `const` you cannot write to it, even after `const_cast`. It doesn't help much to reason about what and how the code does something when you are in the realm of undefined behaviour.
Others have explained that this is undefined behaviour. What's probably happening behind the scenes is that the compiler spots that `c` is const, so allows its value to be cached in a register. When you later read the value of `c` to print it out, the compiler doesn't bother fetching it from memory (it's `const`, so it can't have changed, right?), but just uses the cached value instead.