Q:

Write a C program to print ASCII value of a character

0

C program to print ASCII value of a character

What is ASCII value?

An ASCII value is a code (numeric value) of keys. We put the any character, symbol etc, than the computer can’t understand. A computer can understand only code and that code against each key is known as ASCII Code.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to get ASCII of a character in C

#include <stdio.h>

int main()
{
	char ch;

	//input character
	printf("Enter the character: ");
	scanf("%c",&ch);

	printf("ASCII is = %d\n", ch);
	return 0;
}

Output

First run:
Enter the character: a
ASCII is = 97

Second run:
Enter the character: A 
ASCII is = 65

Here, we just read a character and print it’s using %d format specifier, which is used to print an integer value. When we print the character value using %d the ASCII code prints on the screen.

Since, this is a very simple program for beginners, still you liked the program and its explanation, please share your comments.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now