

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
puts() vs printf() for printing a string in C language
The function puts() and printf() are declared in stdio.h header file and are used to send the text to the output stream. Both have different usages and syntax.
puts()
The function puts() is used to print the string on the output stream with the additional new line character ‘\n’. It moves the cursor to the next line. Implementation of puts() is easier than printf().
Here is the syntax of puts() in C language,
puts(“string”);
If you do not want the cursor to be moved to the new line, use the following syntax.
fputs(string, stdout)
Here is an example of puts() in C language,
Example
#include<stdio.h> int main() { puts("This is a demo."); fputs("No new Line.", stdout); puts(" Welcome!"); getchar(); return 0; }
Output
This is a demo. No new Line. Welcome!
printf()
The function printf() is used to print the text long with the values of variables. The implementation of printf() is complex, that is why it is expensive than puts().
Here is the syntax of printf() in C language,
printf(“string”);
Here is an example of printf() in C language,
Example
#include<stdio.h> int main() { int a = 10; printf("Hello world! \n"); printf("The value of a : %d",a); getchar(); return 0; }
Output
Hello world! The value of a : 10
- Related Questions & Answers
- C++ Program for Expressionless Face Pattern printing
- String Literal Vs String Object in C#
- Printing Pyramid in C++
- char vs string keywords in C#
- printf(), sprintf() and fprintf() in C
- Program for printing array in Pendulum Arrangement.
- Programs for printing pyramid patterns in Python
- Character constants vs String literals in C#
- Printing Heart Pattern in C
- Printing Interesting pattern in C++
- Printing string in plus ‘+’ pattern in the matrix in C++
- What are string literals in C language?
- Printing source of a C program itself
- Execution of printf with ++ operators in C
- Is a book printing press different from a magazine printing press?