KITFORMA · EDITORIAL ANSWER
Why does modifying a char pointer initialized from a string literal crash?
KitForma editorial guide. A pointer to a string literal does not make that literal writable. Attempting to alter its storage has undefined behavior even when the pointer type was accepted by the compiler.
Step-by-step answer
char label[] = "draft", when editing in place. Use const char pointers for read-only borrowed strings. For dynamic copies, allocate sufficient capacity including the terminator and define who frees the result.
Test the mutation on the writable copy and leave the literal untouched. A platform that happens to place literals in writable memory does not provide portability. Const qualification documents intent but is not a substitute for valid storage lifetime.Sources and verification
Sources checked:
Scope: This editorial guide is based on the cited sources and tool behavior. A forum question or a query observed for our site does not establish market search volume, low competition, guaranteed rankings or inadequate answers elsewhere.
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.