OCJP

printf() vs puts() in C Langauge

During earlier post we have come to know that printf() is used to display output to the screen. There are some another functions also that can be used for Output. One of them is ‘puts()’.

puts() is used for String output. Basic Difference between puts() and printf() is :

printf() can be used for all data types like int,char,float,double. puts() is mostly used for String data type.

puts() will move the cursor to the new line after printing. Means anything you print after puts() will be printed in new line without using ‘\n’

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hello ");
printf("Good Morning");
getch();
}
Printf will not start new line after printing the line
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
puts("Hello");
puts("Good Morning");
getch();
}
puts() will send cursor to new line after printing

Means when you use puts(), the next line will be printed in new line without using ‘\n’, either the new line is printf() or puts().

puts() does not print current line as new line.

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?