From Quora: What is the difference between new line\n and carriage return\r in ‘c’ language?

Answer:
Anser by Balagopal Komarath

These are characters in the ASCII character set and are not specific to C.

A newline character ‘\n’ moves the cursor to the beginning of the next line.

A carriage return ‘\r’ moves the cursor to the beginning of the current line.

Try executing the following program.

int main()
{
    printf("This is a line.\r");
    printf("overwrite.\n");
}


It prints "overwrite.line." on a line by itself on the console.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s