ASCII Values are a standard that is followed globally by computers and programming languages. ASCII maps a character, like an English alphabet, mathematical symbols, brackets, etc., to a decimal number that can be converted to binary for the computer to understand. The ASCII value of each character differs, even a lowercase and an uppercase English alphabet don’t have the same ASCII value. In this article, we will discuss methods to find out the ASCII value of a character, the ASCII value of alphabets, numeric digits, and special characters in the C programming Language. We will also explore the difference between ASCII and Unicode, which is another standard used globally to represent strings in computers.
Table of Contents:
What is the ASCII Value of a Character in C
An ASCII value is a numerical representation assigned to a character according to the American Standard Code for Information Interchange (ASCII full form). This standard provides a common way for computers to represent text characters, allowing different systems to interpret the same sequence of bits as the same character.
A computer fundamentally operates on binary data (0s and 1s). When a character, like ‘A’ or ‘$’, is stored in a computer’s memory, it is stored as its corresponding ASCII value in binary form, not the character itself. For example, the character ‘A’ has an ASCII value of 65, which is stored as 01000001 in binary.
When a C program, or any program, works with characters or strings, it is directly manipulating these binary representations of their ASCII values. The character is stored in the binary representation of its ASCII values; therefore, no conversion happens every time a program is executed. Operations like comparison or printing are performed directly on these numerical values. We will see this as a C program in later sections.
Get Certified in C Programming – Build a Strong Programming Foundation!
Enroll Now and start writing efficient C code like a pro!
Why Use ASCII Values in C Programming?
- ASCII values create a standard that is followed universally by systems, programming languages, and more.
- Having standard ASCII values makes dealing with alphabets and characters platform-independent.
- Having ASCII values makes it easier for computers to perform operations like comparisons, sorting, and basic arithmetic on characters. ASCII values contribute to the ease of manipulation.
ASCII Table (0-127) with Characters and Codes
The ASCII standard was originally designed to represent characters using 7 bits, which allows for 27 =128 unique combinations (from 0 to 127). These 128 ASCII values include control characters, digits, uppercase and lowercase English alphabets, and various symbols. This 7-bit ASCII is the universally recognized core standard. Below is the full ASCII table detailing the decimal, the binary representation, and the corresponding character for each of the 128 standard ASCII codes.
- Control Characters, from 0 to 31, are non-printable characters used for controlling devices (like printers) or data transmission.
- Printable Characters, from 32 to 126, include the space character (SP), digits (0-9), uppercase alphabets (A-Z), lowercase alphabets (a-z), and various special characters and punctuation marks.
- The final decimal, 127, is reserved for the DEL character.
How to Find the ASCII Value of a Character in C?
Now that we understand what ASCII values are and why they are important, let’s explore how you can easily find the ASCII values of characters in a C program. C provides straightforward methods to achieve this. Let us look at the two primary methods to find the ASCII value.
This method retrieves the ASCII values of the character you want. It prints it on the console using the format specifier and the printf() function. When you use the format specifier to print a char-type variable, the printf() function automatically interprets the ASCII code of the character and prints it as an integer. Let us look at an example of how this is done.
Code:
Output:
Explanation: In this example, we used the %c format specifier to print the character and the %d format specifier, which is used for integers, to print the ASCII values of the characters.
Method 2: Typecasting Character to Integer for ASCII Value
Using format specifiers was a simple way of finding the ASCII values of characters. There is another method to find the ASCII values: typecasting. Typecasting converts the data type of variables. Since you need to find out the ASCII value of a character that is numerical, you will typecast the char variable to an integer variable. Let us understand this with an example.
Code:
Output:
Explanation: In this example, we printed the ASCII values of alphabets. We created two char variables; one was assigned the alphabet B, and the other was assigned G. After this, we cast both the variables to integers and hence, printed the ASCII values of both the alphabets.
ASCII Values of Alphabets (a-z)
Alphabets are sets of characters that are used to represent text in a string. Like in English, we can have uppercase and lowercase characters for the alphabet, but both will have different ASCII values. For example, the ASCII value of a to z is different from the ASCII value of A to Z. Below, we will provide a table outlining the ASCII values for both uppercase and lowercase alphabets.
Uppercase |
ASCII Value (Uppercase) |
Binary (Uppercase) |
Lowercase |
ASCII Value (Lowercase) |
Binary (Lowercase) |
A |
65 |
1000001 |
a |
97 |
1100001 |
B |
66 |
1000010 |
b |
98 |
1100010 |
C |
67 |
1000011 |
c |
99 |
1100011 |
D |
68 |
1000100 |
d |
100 |
1100100 |
E |
69 |
1000101 |
e |
101 |
1100101 |
F |
70 |
1000110 |
f |
102 |
1100110 |
G |
71 |
1000111 |
g |
103 |
1100111 |
H |
72 |
1001000 |
h |
104 |
1101000 |
I |
73 |
1001001 |
i |
105 |
1101001 |
J |
74 |
1001010 |
j |
106 |
1101010 |
K |
75 |
1001011 |
k |
107 |
1101011 |
L |
76 |
1001100 |
l |
108 |
1101100 |
M |
77 |
1001101 |
m |
109 |
1101101 |
N |
78 |
1001110 |
n |
110 |
1101110 |
O |
79 |
1001111 |
o |
111 |
1101111 |
P |
80 |
1010000 |
p |
112 |
1110000 |
Q |
81 |
1010001 |
q |
113 |
1110001 |
R |
82 |
1010010 |
r |
114 |
1110010 |
S |
83 |
1010011 |
s |
115 |
1110011 |
T |
84 |
1010100 |
t |
116 |
1110100 |
U |
85 |
1010101 |
u |
117 |
1110101 |
V |
86 |
1010110 |
v |
118 |
1110110 |
W |
87 |
1010111 |
w |
119 |
1110111 |
X |
88 |
1011000 |
x |
120 |
1111000 |
Y |
89 |
1011001 |
y |
121 |
1111001 |
Z |
90 |
1011010 |
z |
122 |
1111010 |
Get 100% Hike!
Master Most in Demand Skills Now!
C Program to Find ASCII Values for a-z
In this C code example, we will print the ASCII values of the alphabet. In this example, we will print the ASCII code from just a to e in both uppercase and lowercase, and compare the differences in their values.
Code:
Output:
Explanation: As you can see, the ASCII value of a character A is 65, whereas the ASCII value for the same character in lowercase is 97.
ASCII Values of Numerics and Special Characters
The ASCII value standards also define numeric characters from 0 to 9 and the various special characters, including common punctuation marks, mathematical operators, and various control characters.
Numerics (Digits 0-9)
The numeric characters ‘0’ to ‘9’ are different from the integers 0 to 9. When you declare character ‘0’, the variable that is assigned to the char stores this binary pattern: 00110000, whereas the integer 0 is represented directly in binary based on its mathematical value. Therefore, it is stored using the binary pattern 00000000.
This distinction is crucial:
- A char-type variable holds the ASCII code of a character.
- An int-type variable holds the mathematical value of a number.
Special Characters
Special characters are vital for syntax in programming, formatting, and other ways. For a computer to be able to understand a program, the special characters need to have a binary representation. This is where the ASCII value comes into play. Unlike digits and alphabets, the ASCII values for special characters are generally not sequential.
C Program: Character Digits vs Integer Numbers
Now let us take an example that completely illustrates what happens in the following cases:
- You perform arithmetic operations between two character digits.
- You do arithmetic calculations between one character digit and one integer digit.
- You deal with two integer digits.
Here, we will perform subtraction in all three scenarios.
Code:
Output:
Explanation:
- Scenario 1: Character ‘7’ – Character ‘2’: It will subtract the ASCII values of the two characters (55 – 50). This results in an integer 5, which has a numeric distance. If we cast 5 back to a character, we will see the non-displayable ASCII character ENQ.
- Scenario 2: Character ‘7’ – Integer 2: The character ‘7’ is promoted to its ASCII value (55). Then the integer 2 is subtracted, and we are at 53, which is the ASCII value for the character ‘5.’
- Scenario 3: Integer 7 – Integer 2: This is a normal arithmetic subtraction on the integer values. The output is integer 5, and this is simply the numeric distance away. If that number were an ASCII value, the output would be ENQ – the non-displayable message.
C Program to Print ASCII Values of Symbols
In this example, we will print the ASCII values of a few special characters.
Code:
Output:
Explanation: In this example, we printed the ASCII values of special characters like !, @, #, $, and more.
ASCII vs Unicode: Key Differences for C Programmers
The ASCII table was fundamental to early computing and programming, which is a standardized way to represent English characters and basic symbols. But as things progressed, the 128 characters became limited. It could not represent characters from other languages, special mathematical symbols, or emojis. Therefore, a new encoding was introduced called the Unicode standard. Unicode represents every character from every writing system in the world. Let us look at the key differences between the Unicode characters and ASCII.
Feature |
ASCII (American Standard Code for Information Interchange) |
Unicode (Universal Character Set) |
Character Set Size |
128 characters (7-bit) |
Over 1.1 million code points (uses 8, 16, or 32 bits) |
Encoding Scheme |
Fixed-length 7-bit encoding |
Variable-length encoding (UTF-8, UTF-16, UTF-32) |
Supported Characters |
English letters, digits, and basic symbols only |
Supports characters from most of the world’s writing systems |
Language Support |
Limited to English and a few control characters |
Multilingual — supports almost all human languages |
Memory Usage |
Requires less memory (1 byte) |
May require more memory depending on encoding |
Compatibility |
Widely supported in older systems and C libraries |
Backward-compatible with ASCII in UTF-8 encoding |
Use in C Programming |
Often used for single-language (English) applications |
Preferred for internationalization and multilingual applications |
Examples |
A = 65, a = 97 |
A = U+0041, 中 = U+4E2D |
Master C Programming & DSA – For Free!
Join the Free Course Now and build strong coding and problem-solving skills from the ground up!
Conclusion
ASCII code helps integrate human-readable language into our computers and is fundamental for a programmer. You print the ASCII values of any character using typecasting or format specifiers, and manipulate these ASCII values in your C program. This knowledge becomes especially useful in tasks such as sorting, comparisons, and text processing. ASCII is a lightweight and powerful tool for character manipulation in C.
Ready to advance your C programming skills and prepare for technical challenges? Continue your learning journey with our in-depth tutorials and master common C programming interview questions and answers to boost your confidence!
ASCII Value of a Character in C – FAQs
Q1. How to get the ASCII value of a character in C?
You can get it using printf(“%d”, ‘A’);. This prints the ASCII value of the character.
Q2. What is the ASCII value of A to Z in C?
The ASCII values of ‘A’ to ‘Z’ range from 65 to 90.
Q3. What is the ASCII value of 0 to 9?
Characters ‘0’ to ‘9’ have ASCII values from 48 to 57.
Q4. What is the ASCII value of 1 to 10?
If referring to characters, ‘1’ to ‘9’ are 49 to 57. There’s no single character for 10.
Q5. What is the ASCII number of A to Z?
From ‘A’ to ‘Z’, the ASCII numbers are 65 (A) to 90 (Z).