In C, \r
is a carriage return character, which moves the cursor to the beginning of the current line without advancing to the next line. It is useful in situations where you want to overwrite existing text on the same line. When \r
is encountered, it resets the cursor position to the start of the line, allowing new text to overwrite what was previously displayed.
Example:
This will print “World” by overwriting “Hello” on the same line. The effect varies by terminal.