You can think that '0x2d' is a syntax error and 'x2d' is the correct way of writing.
Specifically, '0x2d' is not a char, but an int. Its value is 0x30783264 or 0x64327830. Which one depends on the implementation.
The C standard says this:
3.1.3.4 Character Constants Semantics
An integer charcter constant has type int [note that it has type char in C++]...The value of an integer character constant containing more than one character...is implementation-defined.
Note that it mentions that the type of this thing in C++ is char. As far as I know, at least VC supports writing like this: 'xe5xadx97', which is a UTF-8 encoded "word".
'0x20' is a multi-character character constant and its corresponding value is 0x30783230
'x20' is a char and its value is 0x20
$ cat 1.c
$ gcc -Wall 1.c
$ ./a.out
You can think that '0x2d' is a syntax error and 'x2d' is the correct way of writing.
Specifically, '0x2d' is not a char, but an int. Its value is 0x30783264 or 0x64327830. Which one depends on the implementation.
The C standard says this:
Note that it mentions that the type of this thing in C++ is char. As far as I know, at least VC supports writing like this:
'xe5xadx97'
, which is a UTF-8 encoded "word".'x2d' is mainly used to represent the encoding of a single-byte character that cannot be displayed directly
'0x2d' should be regarded as a standard hexadecimal string, which can be converted to an int type value through int('0x2d', 16)
'0x2d' is a string containing 4 characters, 'x2d' represents the character '-' (its ASCII value is 0x2d=45).