C Program to find the ASCII Value of a Character


This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem

Write a program in C to find the Ascii value of a character entered by the user and display the result on the screen.

How to find the ASCII Value of a Character in C ?

When the user enters the character A , the value 65 (Ascii value) should be displayed on the screen. Here’s a C program for it.

#include <stdio.h>
int main()
{
    char input;
    // Abundantcode.com program to find the ascii value of a character
    printf("Enter a character: ");

    // Reads character input from the user
    scanf("%c", &input);  
    
    // %d displays displays the integer representation of the character (Ascii value)
    // %c displays the entered character
    printf("ASCII value of %c = %d", input, input);
    return 0;
}

Output

Enter a character: A

ASCII value of A = 65

%d bloggers like this: