Popular Tutorials
Start Learning C++Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
C++ putchar()
The putchar() function in C++ writes a character to stdout.
putchar() prototype
int putchar(int ch);
The putchar() function takes an integer argument to write it to stdout. The integer is converted to unsigned char and written to the file.
It is defined in <cstdio> header file.
putchar() Parameters
ch: The character to be written.
putchar() Return value
On success, the putchar() function returns the character represented by ch. On failure, it returns EOF and sets the error indicator on stdout.
Example: How putchar() function works
#include <cstdio<
int main()
{
for (int i=48; i<58; i++)
{
/* Writes the equivalent character */
putchar(i);
putchar(' ');
}
return 0;
}
When you run the program, the output will be:
0 1 2 3 4 5 6 7 8 9
Also Read:
Did you find this article helpful?