
Where your keyboard probably says "Enter", older keyboards used to say "Return", which was short for Carriage Return. Why did different systems choose different methods? Simply because there was no universal standard. In Unicode, NL is U+0085 NEXT LINE, but the actual EBCDIC value is 0x15.
Old IBM systems that used EBCDIC standardized on NL-a character that doesn't even exist in the ASCII character set. VMS, CP/M, DOS, Windows, and many network protocols still expect both: CR LF. Old (pre-OSX) Macintosh files used just a CR character to indicate a newline. Unix variants (including modern versions of Mac) use just a LF character to indicate a newline. Rather than requiring the pair of control characters, some systems allowed just one or the other. On early serial CRT terminals, CR was one of the ways to control the cursor position in order to update text already on the screen.īut most of the time, you actually just wanted to go to the next line. Some systems overprinted several times to prevent passwords from being visible in hardcopy. This allowed effects like accents, bold type, and underlining. By sending a CR without following it by a LF, you could print over the line you already printed. In the days of teletypes and early technology printers, people actually took advantage of the fact that these were two separate operations. (Unicode encodes this as U+000A LINE FEED.) \x0A (LF) moves the print head down to the next line. (Unicode encodes this as U+000D CARRIAGE RETURN.) \x0D (CR) moves the print head back to the beginning of the line.
move the print head back to the beginning of the line, thenĪSCII encodes these actions as two distinct control characters:. When you wanted to finish the current line and start on the next line, you had to do two separate steps: (This is conceptually the same as a typewriter, except that typewriters typically moved the paper with respect to the print head.) When you send a printable character to the teletype, it prints the character at the current position and moves the head to the next column.
The print head is positioned on some line and in some column. In C and C++, \n is a concept, \r is a character, and \r\n is (almost always) a portability bug.