Why this C program throws segmentation fault at runtime?

前端 未结 3 1330
半阙折子戏
半阙折子戏 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:50

    "random" is a constant string literal. It is placed by OS into the protected Read-Only Memory (CPU is instructed by OS to prevent write operations in this memory). 's' and 't' both point to this protected read-only memory region. Once you tries to write into it, CPU detects this attempt and generates exception.

提交回复
热议问题