C

C Program To Determine The ASCII Value Of A Character

The ASCII value represents English characters as numbers, with each letter assigned a number ranging from 0 to 127. Uppercase Q, for example, has an ASCII value of 81.

Exemplification 1: A program that displays the ASCII value of a user-entered character.

This program displays the ASCII value of the character entered by the user.

#include <stdio.h>
int main()
{
    char ch;
    printf("Enter any character:");

    /* Reads the entered character and stores it
     * into the char variable ch
     */
    scanf("%c", &ch);

    /* Using the format specifiers we can get the ASCII code
     * of a character. When we use %d format specifier for a
     * char variable then it displays the ASCII value of a char
     */
    printf("ASCII value of character %c is: %d", ch, ch);
    return 0;
}

Output:

Enter any character:Q
ASCII value of character Q is: 81

 

Related Articles

Leave a Reply

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

Back to top button