Related Tags

putchar()
c++
function

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

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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.

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

RELATED TAGS

putchar()
c++
function