"0x10"
means the C-string containing 4 characters (plus the ending NUL byte), '0'
, followed by 'x'
, followed by '1'
, followed by '0'
.
"\x10"
means the C-string containing 1 character (plus the ending NUL bytes), the sixteenth character of the ASCII table. The compiler interpret the content of your string by doing the conversion by itself, thus replacing the full sequence \0x10
by its value. Then strtol
is unable to understand this as a representation of an hex number representation, and then returns 0 :
strtol
manual : If no valid conversion could be performed, a zero value is returned
(0L).
Read What does \x mean in c/c++?.