In this example, you will learn how to find the ASCII value of a character.
To understand this example, you should have knowledge of the following C programming topics:
C Variables, Constants, and Literals
In C programming, a character variable holds ASCII value (an integer number somewhere in the range of 0 and 127) as opposed to that character itself. That worth is known as it’s ASCII value.
For example, the ASCII value of ‘A’ is 65.
What this means is that, if you assign ‘A’ to a character variable, 65 is stored in the variable rather than ‘A’ itself.
Now, we should perceive how we can print the ASCII estimation of characters in C programming.
Program to Print ASCII Value
#include <stdio.h> int main() { char c; printf("Enter a character: "); scanf("%c", &c); // %d displays the integer value of a character // %c displays the actual character printf("ASCII value of %c = %d", c, c); return 0; }
Output
Enter a character: G ASCII value of G = 71
In this program, the user is asked to enter a character. The character is stored in variable c.
When the %d format string is used, 71 (the ASCII value of G) is displayed.
When the %c format string is used, ‘G’ itself is displayed.
Please feel free to give your comment if you face any difficulty here.
For more Articles click on the below link.