why printf works on non-terminated string

后端 未结 6 1879
渐次进展
渐次进展 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:34

    There's a good chance that one of the characters after the string is NULL, so printf stops there, furthermore, characters that are not NULL after the memory that you malloced might not be printable characters so you won't notice them in the terminal.

提交回复
热议问题