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.
Undefined behaviour. The compiler is allowed to optimize (e.g. keep in a register) things that it knows are immutable. 

There is a slight chance that marking the char `volatile` would make the compiler respond more in expected fashion. Keep in mind that it is still undefined behaviour nonetheless