C++ putchar()

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
Did you find this article helpful?