+ 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?
2 odpowiedzi
+ 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.
+ 4
Escape sequences in C
https://en.wikipedia.org/wiki/Escape_sequences_in_C