In this post, we are going to write a simple C program to find the ASCII value of any character that a user has entered. If you what is an ASCII value, I will give a simple example here,
Each character whether it can be an Alphabet or Number or Any Symbol holds an ASCII value. For eg., the ASCII value of A is 65 and a is 97 and also for & is 38. So we can easily find out these ASCII values by writing a simple C Program.
Here is the C program to find and print the ASCII value of a character:
//program to find ASCII value of a character
#include <stdio.h>
int main() {
char c;
printf("Enter any character (eg., A or a or $ or 5): ");
scanf("%c", &c);
// %d to display the value of the character
// %c to display the entered character
printf("ASCII value of %c is %d", c, c);
return 0;
}And the sample output of the above program is:
Enter any character (eg., A or a or $ or 5): 5 ASCII value of 5 is 53 -------------------------------- Process exited after 2.726 seconds with return value 0 Press any key to continue . . .
I hope this program is very helpful for you. Subscribe to this blog for more new updates.