Why this C program throws segmentation fault at runtime?

前端 未结 3 1289
半阙折子戏
半阙折子戏 2021-01-27 01:35

I\'m declaring character array as char* string. And then I declare other pointer which again refer to original string, then when I\'m going to change any thing on that string, a

3条回答
  •  后悔当初
    2021-01-27 01:56

    you try to modify the string literal. It is an Undefined Behavoiur and everything may happen including the segfault.

    from the C standard what is an UB:

    —The program attempts to modify a string literal (6.4.5).

提交回复
热议问题