C Program to Read a Character and Displaying Its ASCII Value

ASCII is abbreviated form for American Standard Code for Information Interchange.

Since computers can only understand numbers, so an ASCII code or value is Numeric representation of character such as 'a' or 'A' or '+' etc. Original ASCII code are of 7 bit long and Extended ASCII code are of 8 bit long.

ASCII Code Examples

  1. ASCII value of 'a' is 97, ASCII value of 'b' is 98, ..., ASCII value of 'z' is 122
  2. ASCII value of 'A' is 65, ASCII value of 'B' is 66, ..., ASCII value of 'Z' is 90
  3. ASCII value of '0' is 48, ASCII value of '1' is 49, ...., ASCII value of '9' is 57
  4. ASCII value of '+' is 43, ASCII value of '%' is 37, and so on.

In this C program, given a character we will display ASCII value of given character.

Program


#include<stdio.h>
#include<conio.h>

int main()
{
	 char ch;
	 clrscr();
	 printf("Enter any character: ");
	 scanf("%c", &ch);
	 printf("ASCII value of %c is %d", ch, ch);
	 getch();
	 return(0);
}

Output of the above program :

Run 1:
--------
Enter any character: J ↲
ASCII value of J is 74

Run 2:
--------
Enter any character: p ↲
ASCII value of p is 112

Run 3:
--------
Enter any character: + ↲
ASCII value of + is 43

Run 4:
--------
Enter any character: 7 ↲
ASCII value of 7 is 55

Note: ↲ indicates ENTER is pressed.