Backslash zero delimiter '\0'

杀马特。学长 韩版系。学妹 提交于 2019-12-03 11:11:34

问题


I have seen '\0' to be used as a delimiter in mixed binary files (UTF8 strings + binary data). Could anyone explain what '\0' means or point to a good place to study?


回答1:


It's the null character; more info in this Wikipedia article.




回答2:


The two-character \0 representation is used in C source code to represent the NUL character, which is the (single) character with ASCII value 0.

The NUL character is used in C style character strings to indicate where the end of the string is. For example, the string "Hello" is encoded as the hex bytes:

48 65 6c 6c 6f 00

In this case, the C compiler automatically adds the 00 byte on the end of any double-quoted string. If you wrote the constant as "Hello\0", then the C compiler would generate:

48 65 6c 6c 6f 00 00



回答3:


\0 is shorthand for \000 which is an octal character escape. In general, you can shorten any octal escape that isn't followed by an octal digit. This derives from the original C escape sequences (\n \r \t \f \v \b \000 where the latter is a character value in octal notation; ANSI added some, and \v is somewhat rare these days and many more modern languages don't implement it).



来源:https://stackoverflow.com/questions/6380155/backslash-zero-delimiter-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!