Home » C Basic I/O programs

C program to print ASCII value of a character



In this C program, we are going to learn how to get and print the ASCII value of a given character? This is simple C program, where we will print the ASCII code of a character.
Submitted by Manju Tomar, on November 07, 2017

Given a character and we have to find its ASCII value using C program.

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.

Read more: What is ASCII, list of ASCII codes.

In this program, we are reading two integer numbers in variable a and b and assigning the subtraction of a and b in the variable sub.

Example 1:

Input:
Enter character: a
Output:
ASCII is: 97

Example 2:

Input:
Enter character: A
Output:
ASCII is: 65



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.






Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.