In C, a character variable holds ASCII value (an integer number between 0 and 127) rather than the character itself. You will learn how to find ASCII value in C Programming.
To understand this Program to Find ASCII Value in C, you should have the knowledge of following C programming topics:
- Data Types
- Constants
- Variables
- Input-Output (I/O)
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 ‘A’ is 65.
What this means is that, if you assign ‘A’ to a character variable, 65 is stored in that variable rather than ‘A’ itself.
Program to Print ASCII Value
#include <stdio.h> int main() { char c; printf("Enter a character: "); // Reads character input from the user 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 which is stored in variable C. The ASCII value of that character is stored in the variable C rather than that variable itself.
When %d format string is used, 71 (ASCII value of ‘G’) is displayed.
When %c format string is used, ‘G’ itself is displayed.
Ask your questions and clarify your/others doubts on Find ASCII Value in C by commenting. Documentation.
Please write to us at [email protected] to report any issue with the above content or for feedback.
Related Program