0
Every character in C programming is given an integer value to represent it. That integer value is known as ASCII value of that character. For example: ASCII value of 'a' is 97. Here is the complete list of ASCII value of characters in C programming. When a character is stored in variable of type char, the ASCII value of character is stored instead of that character itself character itself. For example: If you try to store character 'a' in a char type variable, ASCII value of that character is stored which is 97.
In, this program user is asked to enter a character and this program will display the ASCII value of that character.

Source Code


/* Source code to find ASCII value of a character entered by user */

#include <stdio.h>
int main(){
char c;
printf
("Enter a character: ");
scanf
("%c",&c); /* Takes a character from user */
printf
("ASCII value of %c = %d",c,c);
return 0;
}
Output
Enter a character: G
ASCII value of G = 71
Explanation
In this program, user is asked to enter a character and this character will be stored in variable c, i.e., the ASCII value of that character is stored in variable c. When, this value is displayed using conversion format string %c, the actual variable is displayed but, when this variable is displayed using format string %d, the ASCII value of that character is displayed.


Post a Comment

 
Top