why printf works on non-terminated string

后端 未结 6 1925
渐次进展
渐次进展 2021-01-05 15:47

I am wondering how does printf() figure out when to stop printing a string, even I haven\'t put a termination character at the end of the string? I did an experiment by mall

6条回答
  •  孤独总比滥情好
    2021-01-05 16:22

    The random garbage that is after the last byte in the string was null. It was luck. It could fail the next time you run the program or work 100 times in a row. Welcome to pointer errors (and they can be difficult to debug too).

提交回复
热议问题