Because "abc" is a constant string literal. Then you point ptr
to it and try to modify it which is undefined behaviour. Typically string literals are put in a memory section which gets mapped as read-only - hence the access violation.
See also this question: String literals: Where do they go?