\r
is actually carriage return (which takes the cursor to the start of the line).
Your program outputs a new line (\n
) followed by "ab" then backspace (\b
) (over the b) "si", so you now have "asi" on the screen.
The \r
takes the cursor to the start of the line and then outputs "ha" leaving "hai" on the screen.