C90, 6.1.4
If the program attempts to modify a string literal of either form, the behaviour is undefined.
In your case this Undefined behaviour is in your favour so that you are getting Seg fault.Other than this printing pointer using %d
is not a good practice, You should use %p
.
Now from your given Link Answer of Blue Moon
you should always treat p
and p1
as two different pointers (even though they have the same content) as they may or may not point to the same address. You shouldn't rely on compiler optimizations.