What does \x mean in C/C++?

前端 未结 7 1199
一生所求
一生所求 2020-12-08 09:46

Example:

char arr[] = \"\\xeb\\x2a\";

BTW, are the following the same?

\"\\xeb\\x2a\" vs. \'\\xeb\\x2a\'<

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 10:21

    \x indicates a hexadecimal character escape. It's used to specify characters that aren't typeable (like a null '\x00').

    And "\xeb\x2a" is a literal string (type is char *, 3 bytes, null-terminated), and '\xeb\x2a' is a character constant (type is int, 2 bytes, not null-terminated, and is just another way to write 0xEB2A or 60202 or 0165452). Not the same :)

提交回复
热议问题