+ 1

Difference between \n and \r.

"hello\na" and "hello\ra" gives same output. Explain in terms of output and what does carriage return means.

24th Dec 2016, 3:45 PM
rahul
rahul - avatar
5 Respostas
+ 4
\n = newline \r = carriage return
24th Dec 2016, 3:50 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
Ok the result on your screen is the same.. But you should know that this is derived from the printing system.. Think about dot matrix printers (or a typewriter) where the \n command (new line) goes to the new line moving down the roll without changing the position of the head. The \r command (carriage return) moves the head to the first position of the line. In the MsDos based systems in text files the newline is composed by \x0D and \x0A that is the same as \r + \n (in this order). Instead in Unix based system the new line is composed only by \x0A (\n).
24th Dec 2016, 4:26 PM
Michael Isac Girardi
Michael Isac Girardi - avatar
+ 2
In c use only \n
24th Dec 2016, 5:03 PM
Michael Isac Girardi
Michael Isac Girardi - avatar
+ 1
so, there is no difference between \n and \r in new compilers #michael isac Girardi
24th Dec 2016, 4:50 PM
rahul
rahul - avatar
+ 1
can you answer another post of mine about backspace #Girardi
24th Dec 2016, 5:04 PM
rahul
rahul - avatar