What is the difference between newline and carriage return?

prateek pandey October 28, 2012

Can anyone tell me what is the the difference between ‘newline’ and ‘carriage’ return?

  1. Anonymous
    October 31, 2012 at 3:13 pm

    LF: Multics, Unix and Unix-like systems (GNU/Linux, Mac OS X, FreeBSD, AIX, Xenix, etc.), BeOS, Amiga, RISC OS and others.
    CR+LF: Microsoft Windows, DEC TOPS-10, RT-11 and most other early non-Unix and non-IBM OSes, CP/M, MP/M, DOS (MS-DOS, PC-DOS, etc.), Atari TOS, OS/2, Symbian OS, Palm OS
    LF+CR: Acorn BBC and RISC OS spooled text output.
    CR: Commodore 8-bit machines, Acorn BBC, TRS-80, Apple II family, Mac OS up to version 9 and OS-9
    RS: QNX pre-POSIX implementation.

  2. Rob Hindle
    October 29, 2012 at 3:24 pm

    Comes from teletype/printers
    As already explained CR would have returned the print head to the beginning of a line
    LF would feed the paper up one line.
    CR without LF would mean the next line of print would be on top of the first
    LF without CR would mean the next line started to print just below the right hand end of the previous line

    That meant that the printer would normally need both CR and LF at the end of each line of print.

    When computers started to have screens rather than just teletype style input/output it made sense to use the same commands to control the way lines of text were displayed on the screen.

    The representation of CR and LF can vary between computer languages (and operating systems) and sometimes one or both will be treated as a combination of both. If you have a text editor that can display the content of a text file in Hex (hexadecimal) you will often see the Hex representation of CR&LF as 0D0A.
    Programming languages.

    This can cause some oddities when text files are exchanged between systems which use different implementations/interpretations of CR and LF.

  3. Aniket Singh
    October 29, 2012 at 5:58 am

    Today, we will examine something very simple and very generic that can apply to hordes of programming languages. Let’s take a common question that is frequently discussed – What is difference between Line Feed (\n) and Carriage Return (\r)?

    Prior to continuing with this article let us first look into few synonyms for LF and CR.

    Line Feed – LF – \n – 0x0a – 10 (decimal)

    Carriage Return – CR – \r – 0x0D – 13 (decimal)

    Now that we have understood that we have two different options to get new line, the question that arises is – why is it so?

    The reason is simple. Different operating systems have a different way of understanding new line. Mac only understands ‘\r’ as new line, while Unix and Linux understand ‘\n’ as new line character. Our favorite OS windows needs both the characters together to interpret as new line, which is ‘\r\n’. This is the reason why a file created in one OS does not open properly in another OS and makes it messy.

    Now, let us see how we can create a new line in SQL Server. It is a very simple script yet very useful when we have to do run print something or generate scripts. I have illustrated two examples below that are very easy to understand. In the first example, there are no new line chars inserted and for the same, everything is displayed in a single line. However, in the second example, new line char is inserted and the lines are separated with a new line.

  4. Ahmed Khalil
    October 28, 2012 at 11:14 pm

    it is usually seen in programming languages,
    the following link give you answer to your question


    • Boni Oloff
      October 29, 2012 at 3:14 am

      Yap, it is used in programming language..

    • Harish Jonnalagadda
      October 29, 2012 at 8:27 pm

      Thanks for the link!

  5. Anonymous
    October 28, 2012 at 10:30 pm

    These characters come from the old teletype days. A carriage return would do exactly that, return the print head carriage to the beginning of the line. A newline character would simple shift the roller to the next line without moving the print head. When computers entered the scene and the characters were used in files, the exact meaning of them would depend on the developers of the operating systems. To go to the next line in a text file, Microsoft decided to use both characters to represent the move to the next line in the document just like you would with a teletype. Apple decided that the carriage return itself would be used for both actions while Unix systems used the newline by itself for the same result.

Ads by Google