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 657565-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;
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved