Quote:
Originally Posted by fundorin
We assign "\x0B" text string as a value to num3. Cannot be printed as a string. [B]Why?!
|
That example is now part of clear code written for learning and testing purposes. Makes it easier to hazard an answer. Thanks.
This is probably because rather than string, "\x0B" is turned by the compiler into a single character because \x is an escape character so the executed code will end up with the single character byte for hex 0B, which is a non printable character (a vertical tab) when printf()ed with %s or other format conversion.
If one uses "\\x0B" instead, then it has an \ escape character to escape the escape character \ followed by x so probably produces the string expected.
Information about escape characters in C strings explains this. It's an example of a nasty kind of bug where a single character (in this case omitted) compiles without error but has completely changed the programmer's intention.