The getchar() function reads a character from the terminal and returns it as an integer. This function reads only single character at a time.


The putchar() function displays the character passed to it on the screen and returns the same character. This function too displays only a single character at a time.

#include<stdio.h>
void main( )
{
    int c;
    printf("Enter a character");

    /*
        Take a character as input and store it in variable c
    */

    c = getchar();

    /*
        display the character stored in variable c
    */

    putchar(c);
}
Output :
Enter a character
(Suppose we entered P)
P

When you will compile the above code, it will ask you to enter a character. When you will enter the character, it will display the character you have entered.

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post