C Program to Find ASCII Value of Character

Simple-C-Program

In this article, we are going to learn how to Find the ASCII Value of a Character. In computer science, we have ASCII format that has a unique representation of all characters and numbers. In this program, we will try to find the ASCII value which is associated with each character.

C Program to Print ASCII Value of character


In this example, we are going to learn how to find the ASCII value of a character. We will ask the user to enter a character input. We will take this input value and will try to find the ASCII value of this character. In C language, we can use the %d format specifier to find the ASCII value. When we take input from the user we will take input as %c and when we try to print this character by using %d then we will get its ASCII value.

#include <stdio.h>
int main() 
{  
    char ch;
    printf("Please enter a character: ");
    scanf("%c", &ch);  
    
    printf("The ASCII value of %c = %d", ch, ch);
    
    return 0;
}

Output

Please enter a character: y
The ASCII value of y = 121