What is the difference between/r and/n, how should we use it when coding, let's take a look at it below.
the difference:
/ r:
Full name: Carriage Return (Carriage is a "car", a component on the printer)
Abbreviation: Return
Abbreviation: R
Ascii code: 13
Function: Move the cursor to the far left of the current line
/n:
Full name: New Line
Alias: LINE Feed
Abbreviation: n
ASCII code: 10
Role: Move the cursor downward
How does different operating systems represent "Enter+Enter" (that is, the end of a line):
Unix, Linux:/N means that Enter+change,/r does not make sense
Windows, DOS:/R/N indicates that Enter+changes, the order cannot be changed
MAC:/R indicates that Enter+Change
history:
Mechanical English typing machine: On the typewriter, there is a component called "Carriage". Each of a word is entered, and the "word car" advances. When the loser is full, the user will promote the "car" to the starting position. At this time Move it down) to start entering the next line. These two actions are called "Enter", which is equivalent to the "Enter" key in the current keyboard.
Electric passage: (Teletype Model 33, the TTY concept under Linux/Unix also comes from here) 10 characters per second. However, it has a problem that when you finish the row, you need to use it for 0.2 seconds to just type two characters. If there are new characters in this 0.2 seconds, then this character will be lost.
As a result, the developer thought about a way to solve this problem, that is, add two characters to the end of each line. One is called "Return" and told the typo to position the printed head on the left boundary; the other is called "Newline", and tell the typeer to move the paper down. These two actions were abbreviated as "/r" and "/n".
How to use in the programming language:
Because "/n" is represented by "/n" in UNIX, "/n" can be used directly in the C language (and other C language, such as C ++, Java), which will be automatically used in different operating systems. Converted into the corresponding character (such as "/r/n" in Windows).
The above is all the contents of this article. I hope everyone can like it.