Last C programming lesson. Why is the string disappearing? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Last C programming lesson. Why is the string disappearing?

The last lesson features the following code: #include <stdio.h> #define TO_STR(x) #x int main() { printf("%s\n", TO_STR( 123\\12 )); return 0; } Output: 123\12 If I put only a single backslash between the numbers as in the following code, the output changes #include <stdio.h> #define TO_STR(x) #x int main() { printf("%s\n", TO_STR( 123\12 )); return 0; } Output: 123 Could anyone tell me why only 123 appears and the number 12 disappears?

26th Mar 2023, 10:12 PM
Matheus Ferreira Faria
2 Answers
+ 7
The number after a single backslash gets interpreted as an octal number for an ASCII character code. In this case \12 becomes the linefeed control character. Try changing it to TO_STR( 123\101 ) and see what happens.
26th Mar 2023, 11:52 PM
Brian
Brian - avatar
26th Mar 2023, 11:29 PM
SoloProg
SoloProg - avatar