What is the putchar() function in C++?

In C++, the putchar() function writes a character to stdout.

Syntax

The putchar() function takes an integer argument to write it to stdout. The integer is converted to unsigned char and written to the file.

svg viewer

Upon success, the putchar() function returns the character represented by ch; upon failure, the function returns EOF and sets the error indicator on stdout.

putchar() is defined in the <cstdio> header file.

Code

The example below outputs characters equivalent to the integer values ranging from 65āˆ’7565-75 (i.e., the first ten uppercase letters):​

#include <iostream>
using namespace std;
#include <cstdio>
int main()
{
for (int i=65; i<75; i++)
{
/* Writes the equivalent character */
putchar(i);
putchar(' ');
}
return 0;
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
šŸ† Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved