Home »
C solved programs »
C basic programs
C program to print ASCII value of a character
In this C program, we are going to learn how to get and print the ASCII value of a given character? This is simple C program, where we will print the ASCII code of a character.
Submitted by Manju Tomar, on November 07, 2017
Given a character and we have to find its ASCII value using C program.
What is ASCII value?
An ASCII value is a code (numeric value) of keys. We put the any character, symbol etc, than the computer can’t understand. A computer can understand only code and that code against each key is known as ASCII Code.
Read more: What is ASCII, list of ASCII codes.
In this program, we are reading two integer numbers in variable a and b and assigning the subtraction of a and b in the variable sub.
Example 1:
Input:
Enter character: a
Output:
ASCII is: 97
Example 2:
Input:
Enter character: A
Output:
ASCII is: 65
Program to get ASCII of a character in C
#include <stdio.h>
int main()
{
char ch;
//input character
printf("Enter the character: ");
scanf("%c",&ch);
printf("ASCII is = %d\n", ch);
return 0;
}
Output
First run:
Enter the character: a
ASCII is = 97
Second run:
Enter the character: A
ASCII is = 65
Here, we just read a character and print it’s using %d format specifier, which is used to print an integer value. When we print the character value using %d the ASCII code prints on the screen.
Since, this is a very simple program for beginners, still you liked the program and its explanation, please share your comments.
C Basic Programs »