How to Find ASCII Value in C

How to Find ASCII Value in C

In this article, we are going to discuss how to find the ASCII value of the character. So this is a very simple program so let’s start implementing this.

ASCII – American standard code information interchange.

For example-

input:

so basically we are taking user input in these programs, so we are going to take characters from the user.

For example, we take &

Logic:

We have to simply print the ASCII value of the character for that we simply print the value of the character in int data type.

Output :

According to our input, we get the ASCII value of our character as follows:

The ASCII value is 38

So let’s try to implement this example in our program!

C program to find the ASCII value of the character.

#include<stdio.h>
int main(){
char ch ;
printf(“Enter character :”);
scanf(“%c”, &ch);
printf(“The ASCII value is %d”, ch);
return 0;

}

Output

Enter character :&

The ASCII value is 38

Step 1: First take a char-type variable to take input from the user.

Step 2: use scaf() to store the value of the character and for that, we use %c format specifier because we get a character from the user. From the above program, we can see that.

Step 3: After these two steps simply use printf() statement to get our output and for that, we simply use %d format specifies because we get output in the form of an integer.

In this way, we simply understand how to find the ASCII value of the character. I hope this thing is clear to you. So for now keep learning and keep exploring!