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 6541707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:08:15+00:00 2026-05-25T11:08:15+00:00

I have C code like this: #include<stdio.h> int main() { printf(Hey this is my

  • 0

I have C code like this:

#include<stdio.h>
int main()
{
    printf("Hey this is my first hello world \r");
    return 0;
}

I have used the \r escape sequence as an experiment. When I run the code I get the output as:

o world

Why is that, and what is the use of \r exactly?

If I run the same code in an online compiler I get the output as:

Hey this is my first hello world

Why did the online compiler produce different output, ignoring the \r?

  • 1 1 Answer
  • 0 Views
  • 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-25T11:08:16+00:00Added an answer on May 25, 2026 at 11:08 am

    \r is a carriage return character; it tells your terminal emulator to move the cursor at the start of the line.

    The cursor is the position where the next characters will be rendered.

    So, printing a \r allows to override the current line of the terminal emulator.

    Tom Zych figured why the output of your program is o world while the \r is at the end of the line and you don’t print anything after that:

    When your program exits, the shell prints the command prompt. The terminal renders it where you left the cursor. Your program leaves the cursor at the start of the line, so the command prompt partly overrides the line you printed. This explains why you seen your command prompt followed by o world.

    The online compiler you mention just prints the raw output to the browser. The browser ignores control characters, so the \r has no effect.

    See https://en.wikipedia.org/wiki/Carriage_return

    Here is a usage example of \r:

    #include <stdio.h>
    #include <unistd.h>
    
    int main()
    {
            char chars[] = {'-', '\\', '|', '/'};
            unsigned int i;
    
            for (i = 0; ; ++i) {
                    printf("%c\r", chars[i % sizeof(chars)]);
                    fflush(stdout);
                    usleep(200000);
            }
    
            return 0;
    }
    

    It repeatedly prints the characters - \ | / at the same position to give the illusion of a rotating | in the terminal.

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

Sidebar

Related Questions

Say you have a C code like this: #include <stdio.h> int main(){ printf("Hello, world!\n");
I have written a simple Hello World program. #include <stdio.h> int main() { printf(Hello
Consider this program: #include <stdio.h> int main() { printf(%s\n, __FILE__); return 0; } Depending
see i have code like #include<stdio.h> #include<pthread.h> #include<string.h> void* thread_function(void) { printf (This is
If I have a global static variable x like in this code #include <stdio.h>
I have a simple problem; Here is the code : #include<stdio.h> main(){ int input;
This code compiles and produce output like I would expect. #include <stdio.h> int* ar[];
I have the code : #include<stdio.h> void main(){ int i; float a=5.2; char *ptr;
I have the following piece of code: #include <stdio.h> int main ( int argc,
How exactly does fork() work? The following code #include <stdio.h> int main (int argc,

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.