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

  • Home
  • SEARCH
  • 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 9232137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:14:31+00:00 2026-06-18T06:14:31+00:00

I was wondering the difference between puts() and printf() functions while using sleep() function.

  • 0

I was wondering the difference between puts() and printf() functions while using sleep() function.

Here is my code(In C language):

printf("hello, world");
sleep(1);
printf("Good, bye!");

After compiling and running the program, it seems that it will sleep first and then print “hello, worldGood, bye!”

However, if using puts() instead of printf(), it will print “hello, world” then sleep, and finally print “Good, bye”.

puts("hello, world");
sleep(1);
puts("Good, bye!);
  • 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-06-18T06:14:33+00:00Added an answer on June 18, 2026 at 6:14 am

    This is because of buffering – by default, standard out buffers up to each new line. printf() does not include a newline, so output isn’t flushed. puts() includes a newline, so output is flushed.

    You can cause printf() to flush by putting a newline:

    printf("hello, world\n");
    

    or by calling fflush() directly:

    fflush(stdout);
    

    For more about buffering, see the man page for setbuf():

    The three types of buffering available are unbuffered, block buffered, and
       line buffered.  When an output stream is unbuffered, information appears on
       the destination file or terminal as soon as written; when it is block 
       buffered many characters are saved up and written as a block; when it 
       is line buffered characters are saved up until a newline is output or input
       is read from any stream attached to a terminal device (typically stdin).
       ....
       If a stream refers to a terminal (as stdout normally does) it is 
       line buffered. 
       ....
       The standard error stream stderr is always unbuffered by default.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering what's the actual difference between calling Thread.Sleep(1) and calling SwitchToThread (if we
I was wondering if there are any difference between function __construct() { parent::__construct(); $this->load->
I wondering whats the difference between url and destination using httpservice in flex. I
I am wondering about performance difference between stored procedure and scalar-valued function. For now
I am wondering if there is a difference between the two lines of code
I was wondering what is the difference between these two lines of code? int
I was wondering if below code has any difference between #1, #2 and #3
I'm wondering what's the difference between this code: var c = [{test: 1}]; and
I am wondering whether there is any difference between inlining functions on a linker
I was wondering about the difference between using a Control’s Hide() method compared to

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.