When we can or cannot modify String Literals [duplicate]

拈花ヽ惹草 提交于 2019-12-02 13:34:20

TL;DR -- Never.

Any attempt to modify a string literal invokes undefined behavior.

To quote the C11 standard, chapter §6.4.5, String literals

[...]. If the program attempts to modify such an array, the behavior is undefined.

§ "Above Code is working fine on my system".

Yes, welcome to the world of undefined behavior, which includes working as (wrongly) expected.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!