C Program to Find ASCII Value of a Character

ASCII Value Character

C Program to Find ASCII Value of a Character

Before writing a C program, first let us understand what is ASCII?

ASCII stands for American Standard Code for Information Interchange. It is a character encoding standard that is used for electronic communication.

Program

        
#include <stdio.h>

int main ()
{
    char ch;
    printf("Enter a character : ");
    scanf("%c", &ch);
    
    printf("ASCII value of character %c is %d", ch, ch);
    return 0;
}             
        
    

Let's understand Program

In this program, the user is asked to enter a character. The character is stored in variable ch.

When %d format specifier is used, the ASCII value of character ch is displayed.

When %c format specifier is used, the character entered by user is displayed.


Output 1

        
Enter a character : C
ASCII value of character C is 67           
        
    

Output 2

        
Enter a character : 5
ASCII value of character 5 is 53           
        
    

Let's understand outputs

In Output 1, the user entered character C, so the output of character C is 67 (ASCII value).

In Output 2, the user entered character 5, so the output of character 5 is 53 (ASCII value).




Join Our Social Media Connections

Post a Comment

0 Comments