What is the difference between a "line feed" and a "carriage return"?

StringNewlineLine BreaksCarriage ReturnLinefeed

String Problem Overview


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.

String Solutions


Solution 1 - String

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.

Solution 2 - String

Since I can not comment because of not having enough reward points I have to answer to correct answer given by @Burhan Khalid.
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 horizontly and Line feed shifts the cursor to the next line vertically.Combination of both gives you new line(\n) effect.
Reference - https://en.wikipedia.org/wiki/Carriage_return#Computers

Solution 3 - String

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.

Solution 4 - String

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 examle, 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpheromixView Question on Stackoverflow
Solution 1 - StringTsunamisView Answer on Stackoverflow
Solution 2 - StringMonalisa DasView Answer on Stackoverflow
Solution 3 - StringBurhan KhalidView Answer on Stackoverflow
Solution 4 - StringMichael OtterbineView Answer on Stackoverflow