🚀Beginner

Print ASCII Value of a Character

Get ASCII value of a character

ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns a unique number (0-127) to each character. This program shows how to find the ASCII value of any character entered by the user.

🔤 What is ASCII?

Computers only understand numbers. ASCII provides a way to represent characters as numbers:

  • 'A' is stored as 65
  • 'a' is stored as 97
  • '0' (character) is stored as 48

C Program to Print ASCII Value

ascii_value.c
C
1#include <stdio.h>
2
3int main() {
4 // Declare a character variable
5 char ch;
6
7 // Get character from user
8 printf("Enter a character: ");
9 scanf("%c", &ch);
10
11 // Print character and its ASCII value
12 // %c prints as character, %d prints as integer (ASCII)
13 printf("ASCII value of '%c' is %d\n", ch, ch);
14
15 return 0;
16}
Output

Enter a character: A

ASCII value of 'A' is 65

How It Works

In C, a char is actually stored as a small integer (1 byte, value 0-255). The same variable can be printed as:

%c
Prints as character: A
%d
Prints as number: 65

Complete ASCII Table Reference

A-Z
65-90
Uppercase letters
a-z
97-122
Lowercase letters
0-9
48-57
Digit characters
Space
32
Space character
!
33
Exclamation
@
64
At symbol
\n
10
Newline
\t
9
Tab

Useful Applications

Convert Uppercase to Lowercase

main.c
C
1char upper = 'A';
2char lower = upper + 32; // 'a' (65 + 32 = 97)

Check if Character is Digit

main.c
C
1if (ch >= '0' && ch <= '9') // ASCII 48-57
2 printf("It's a digit!");

📝 Key Takeaways

char stores characters as integers
%c prints character, %d prints ASCII
'A'-'Z' = 65-90, 'a'-'z' = 97-122
Difference between upper/lower case is 32

Want to Learn More?

Explore our comprehensive tutorials for in-depth explanations of C programming concepts.

Browse Tutorials
Back to All Examples