View Single Post
Old 01-10-2018, 07:56 AM   #40
goldenarpharazon
Human being with feelings
 
Join Date: Feb 2016
Posts: 189
Default

Quote:
Originally Posted by fundorin View Post
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.

Last edited by goldenarpharazon; 01-10-2018 at 12:48 PM. Reason: Better explanation with solution
goldenarpharazon is offline   Reply With Quote