Backslash zero delimiter '\0'

后端 未结 3 679
余生分开走
余生分开走 2021-02-05 05:20

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

3条回答
  •  离开以前
    2021-02-05 05:35

    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
    

提交回复
热议问题