If there are two keywords then they must have their own meanings. So I want to know what makes them different and what their code is.
-
2Have a look at Wikipedia: en.wikipedia.org/wiki/Carriage_Return#Computers– exicOct 5, 2012 at 13:54
-
5Possible duplicate of What are carriage return, linefeed, and form feed?– jtbandesAug 9, 2016 at 6:05
-
3Have a look at this article, It clears out everything impeccably digital.ni.com/public.nsf/allkb/…– Rohit SalujaOct 2, 2016 at 8:08
-
Canonical candidate (2009): Difference between CR LF, LF and CR line break types?– Peter MortensenFeb 10 at 13:13
4 Answers
A line feed means moving one line forward. The code is \n
.
A carriage return means moving the cursor to the beginning of the line. The code is \r
.
Windows editors often still use the combination of both as \r\n
in text files. Unix uses mostly only the \n
.
The separation comes from typewriter times, when you turned the wheel to move the paper to change the line and moved the carriage to restart typing on the beginning of a line. This was two steps.
-
29you'd think even old typewriters should have thought about making \n represent two steps.– ColacXJul 30, 2014 at 18:47
-
34@ColacX It is often useful to perform a carriage return without a line feed when overwriting the text on the current line is desired. This applies to both typewriters and terminals. Dec 29, 2014 at 20:06
-
3So, in Windows, the proper sequence for the end of a line would look like
\n\r
?– DelfinoApr 7, 2015 at 3:25 -
37@Delfino not really. On mechanical printers, it made sense to initiate a carriage return earlier, since it's slower, and feed the line while the carriage is still moving. Apr 15, 2015 at 10:31
-
7
In very layman language Enter key press is combination of carriage return and line feed.
Carriage return points the cursor to the beginning of the line horizontally and Line feed shifts the cursor to the next line vertically. Combination of both gives you the new line (\n
) effect.
Reference: https://en.wikipedia.org/wiki/Carriage_return#Computers
-
Also, it become the difference between breaking line and breaking paragraph when computers replaced typewriters - text processing.– GustavoApr 24, 2017 at 22:58
-
This seems to be talking about Windows only. It's sort of correct for Unix-like systems, but text files only contain the newline character,
\n
, which appears as a newline + carriage return when displaying it on the screen.– wjandreaDec 31, 2020 at 3:34
Both of these are primary from the old printing days.
Carriage return is from the days of the teletype printers/old typewriters, where literally the carriage would return to the next line, and push the paper up. This is what we now call \r
.
Line feed LF
signals the end of the line, it signals that the line has ended - but doesn't move the cursor to the next line. In other words, it doesn't "return" the cursor/printer head to the next line.
For more sundry details, the mighty Wikipedia to the rescue.
-
16I believe the carriage return refers to moving to the beginning of the same line, rather than moving to the next line. The typewriter analogy refers to both moving down to the next line vertically (line feed) and returning to the beginning of the line horizontally (carriage return). en.wikipedia.org/wiki/Carriage_return– FeckmoreJan 17, 2015 at 15:53
Both "line feed' (0x0A or 10) and 'carriage return' (0x0D or 13) are single-byte values. These values are the accepted standard for LF/CR. Most languages will type these as 'characters.' You can find these values on any standard ASCII table.
For example, in C# a string such as:
String str = "\n\r";
is two characters long (ignoring the hidden end null character '0x00' required in string types). However, you could make an equivalent array of type character such as:
char[] c = new char[](){0x0A,0x0D}; // LF, CR