Segmentation fault (core dumped) in a simple C code

前端 未结 3 530
天涯浪人
天涯浪人 2021-01-20 04:37

I am new in C. I am referring to the book \"The C Programming Language\" by Brian W Kernighian and Dennis Ritchie. There is a code for pointer increment and assignment give

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-20 05:11

    When ever we say *s = "hello" , s is pointing to an address which is present in text segment("hello" goes into text segment). So obviously changing the value of text segment results in SEGV termination.

    And for s[] = "hello" if we do *s++, we are incrementing (modifying) the base address so we got "lvalue required as increment operand" error.

提交回复
热议问题