C putchar() Function Tutorial

  • Post author:
  • Post category:C

In this section, we will learn what the putchar() function is and how to use it in C.

What is putchar() Function in C?

The function `putchar()` is used to send one character to the output stream.

C putchar() Function Syntax:

int putchar(int char)

C putchar() Function Parameters:

This function takes one argument, and that is the character that we want to send to the output.

Note: you might want to read the data-type section as well in order to understand why characters are treated as integer.

C putchar() Function Return Value:

If the operation of sending the argument of the function to the output was successful, the function will return that character as a result. If there was a problem, `EOF` will be returned as the value of this function, which is equal to the value -1.

Example: using putchar() function in C

#include <stdio.h>

int main() {


    char c = 'O' ;

    char returnedValue = putchar(c);

    printf("\nThe returned value of calling putchar function is: %c",returnedValue);

    return 0;
}

Output:

O

The returned value of calling putchar function is: O

Leave a Reply