Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 448001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:37:34+00:00 2026-05-12T21:37:34+00:00

What’s the difference between \n (newline) and \r (carriage return)? In particular, are there

  • 0

What’s the difference between \n (newline) and \r (carriage return)?

In particular, are there any practical differences between \n and \r? Are there places where one should be used instead of the other?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:37:35+00:00Added an answer on May 12, 2026 at 9:37 pm

    In terms of ascii code, it’s 3 — since they’re 10 and 13 respectively;-).

    But seriously, there are many:

    • in Unix and all Unix-like systems, \n is the code for end-of-line, \r means nothing special
    • as a consequence, in C and most languages that somehow copy it (even remotely), \n is the standard escape sequence for end of line (translated to/from OS-specific sequences as needed)
    • in old Mac systems (pre-OS X), \r was the code for end-of-line instead
    • in Windows (and many old OSs), the code for end of line is 2 characters, \r\n, in this order
    • as a (surprising;-) consequence (harking back to OSs much older than Windows), \r\n is the standard line-termination for text formats on the Internet
    • for electromechanical teletype-like “terminals”, \r commands the carriage to go back leftwards until it hits the leftmost stop (a slow operation), \n commands the roller to roll up one line (a much faster operation) — that’s the reason you always have \r before \n, so that the roller can move while the carriage is still going leftwards!-) Wikipedia has a more detailed explanation.
    • for character-mode terminals (typically emulating even-older printing ones as above), in raw mode, \r and \n act similarly (except both in terms of the cursor, as there is no carriage or roller;-)

    In practice, in the modern context of writing to a text file, you should always use \n (the underlying runtime will translate that if you’re on a weird OS, e.g., Windows;-). The only reason to use \r is if you’re writing to a character terminal (or more likely a “console window” emulating it) and want the next line you write to overwrite the last one you just wrote (sometimes used for goofy “ascii animation” effects of e.g. progress bars) — this is getting pretty obsolete in a world of GUIs, though;-).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the difference between newLine() and carriage return (\r)? Which one is best
Is there any practical difference between a Set and Collection in Java, besides the
The difference between Chr and Char when used in converting types is that one
Is there any tangible difference between the two forms of syntax available for creating
Is there any difference between ReferencePath with condition '%(CopyLocal)'=='true' and ReferenceCopyLocalPaths ? The question
Any difference between a = session.query(Accounts).filter(Accounts.key = 4).first() and a = session.query(Accounts).filter(Accounts.key = 4)[0]
Is there a difference between the two expressions: (*x)++ and ++(*x) I can see
Is there a semantic difference between auto const and const auto , or do
What is the difference between these two? From Ruby, I am used to apple
What is the difference between the override and reintroduce directives? And when should I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.