\b
and \r
are rarely used in practice. I just found out that I misunderstood these two escape sequences. A simple test:
printf("foo\bbar\n");
I expected it to output fobar
, because \b
will backspace the cursor, and b
will overwrite the second o
, but instead it outputs: foobar
The same is with \r
:
printf("foo\rbar\n");
I thought \r
will move the cursor to the beginning of the current line, so bar
will replace foo
, so the final output should be bar
. However, it actually outputs:
foo
bar