Segmentation fault (core dumped) in a simple C code

前端 未结 3 532
天涯浪人
天涯浪人 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 04:55

    The problem is that printf expects the first parameter to be a char *, that is, something that points to a character, or the address of a character. When you say printf(*s) you're passing it an actual character, i.e. a number from 0 to 255 or -128 to 127, and the program is going to treat that number as an address, which isn't going to be a valid address on your system.

提交回复
热议问题