C Program to Find ASCII Value of a Character
In this example, we will learn to find the ASCII value of a character.
Remainder :
To understand this example, you should have the knowledge of the following C programming topics:
What is ASCII value ?
In C programming, when we store a character variable then the variable does not store the character itself , it stores the ASCII value (an integer number between 0 and 127) of that character.
For example,
the ASCII value of 'I'
is 73.
It means, when we store the character 'I' in a variable then the integer value 73 is stored in that variable rather than itself.
Program to Print ASCII Value
#include <stdio.h>
int main() {
char a;
printf("Enter a character : ");
scanf("%c", &a);
printf("ASCII value of %c = %d", a, a);
return 0;
}
Output
Enter a character : r
ASCII value of r = 114
Working of the above program
- First we declare a character variable a to store character entered by the user.
char a;
printf("Enter a character : ");
scanf("%c", &a);
printf("ASCII value of %c = %d", a, a);