Categories
2. Input and Output

ASCII Value

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

    // When %c is used, a character is displayed
    printf("You entered %c.\n",chr);  

    // When %d is used, ASCII value is displayed
    printf("ASCII value is %d.", chr);  
    return 0;
}

Output

Enter a character: g
You entered g.
ASCII value is 103.

Leave a Reply

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