C Program to Find ASCII Value of a Character

 C Program to Find ASCII Value of a Character 


In C programming, a character variable holds ASCII value (an integer number between 0 an 127) rather than character itself. You will learn how to find ASCII value of a character in this program.

A character variable holds ASCII value (an integer number between 0 and 127) rather than that character itself in C programming. That value is known as ASCII value.




For example, ASCII value of 'B' is 66.

What this means is that, if you assign 'B' to a character variable, 66 is stored in that variable rather than 'B' itself.

Program to Print ASCII Value :


#include
void  main()
{
    char ch;
    printf("Enter a character: ");

    // Reads character input from the user
    scanf("%c", &ch);

    // %d displays the integer value of a character
    // %c displays the actual character
    printf("ASCII value of %c = %d", ch, ch);

}



output:

Enter a character: E
ASCII value of E =69


In this program, user is asked to enter a character which is stored in variable ch. The ASCII value of that character is stored in variable ch  rather than that variable itself.


*

Post a Comment (0)
Previous Post Next Post