Categories
Input and Output

C Character I/O

#include <stdio.h>
int main()
{
    char chr;
    printf("Enter a character: ");
    scanf("%c",&chr);     
    printf("You entered %c.", chr);  
    return 0;
}   

Output

Enter a character: g
You entered g

When a character is entered by the user in the above program, the character itself is not stored. Instead, an integer value (ASCII value) is stored.

And when we display that value using %c text format, the entered character is displayed. If we use %d to display the character, it’s ASCII value is printed.

Leave a Reply

Your email address will not be published. Required fields are marked *