• Post author:
  • Reading time:1 mins read
  • Post category:C Programs

In this programming tutorial, you will be able to learn how to print the asci value of a character.

In c programming language, the character variable holds the ASCII value of the character. ASCII numbers range from 0 to 127. ASCII code is represented by the number.

Find ASCII Value of a Character Entered by the User Using C Program

Methodology

  • Input character.
  • Print the character and specify the format specifier as %d.

Program

#include<stdio.h>
int main()
{
  char var1;
  printf("Enter the character \n");
  scanf("%c",&var1);
  printf("The ASCII value for entered character is %d \n",var1);
  return 0;
}

Output

Find ASCII Value of a Character Entered by the User Using C Program

Code Explanation

In the above program, the user is asked to enter the character. Entered character is stored in var1.

Print the character as a number by specifying %d as format specifier.


People also ask

How do I get the ASCII value of a character in C?

As ASCII value is an integer value we use placeholder %d to find ASCII value of a character in C.

How many types of ASCII are there?

There are two types of ASCII codes:ASCII-7 and ASCII-8.