Program to Print ASCII Value of a Character in C
ASCII Value :
On this page we will discuss about how to find the ASCII value of a character in C programming language. Each character is assigned an ASCII value. In C, characters are stored in the memory using their ASCII values.
ASCII Code:
- ASCII stands for American Standard Code for Information Interchange.
- A character encoding scheme used in communications is called ASCII.
- 256 ASCII characters are available, but we only use 128 of them (0 to 127).
- These include numbers, punctuation marks, capital and lowercase characters, and more.
- In C, a character variable holds the character’s ASCII value (instead of the character itself).
- The character variables in numbers are represented by the ASCII value.
- For instance, “A” has the ASCII value of 65.
Now lets see Program for ASCII values in C –
ASCII Value Table :
ASCII Table for Uppercase Character
Character | ASCII Value |
---|---|
A | 65 |
B | 66 |
C | 67 |
D | 68 |
E | 69 |
F | 70 |
G | 71 |
H | 72 |
I | 73 |
J | 74 |
K | 75 |
L | 76 |
M | 77 |
N | 78 |
O | 79 |
P | 80 |
Q | 81 |
R | 82 |
S | 83 |
T | 84 |
U | 85 |
V | 86 |
W | 87 |
X | 88 |
Y | 89 |
Z | 90 |
ASCII Table for Lowercase Character
Character | ASCII Value |
---|---|
a | 97 |
b | 98 |
c | 99 |
d | 100 |
e | 101 |
f | 102 |
g | 103 |
h | 104 |
i | 105 |
j | 106 |
k | 107 |
l | 108 |
m | 109 |
n | 110 |
o | 111 |
p | 112 |
q | 113 |
r | 114 |
s | 115 |
t | 116 |
u | 117 |
v | 118 |
w | 119 |
x | 120 |
y | 121 |
z | 122 |
Example 1 :
Write a program to print ascii value of given character.
Run
#include<stdio.h> int main () { char ch; printf ("Enter the Character = "); scanf ("%c", &ch); printf ("\nThe ASCII Value of %c = %d", ch, ch); return 0; }
Output:
Enter the Character = S The ASCII Value of S = 83
Example 2 :
Write a program to print all the ascii value of given input character.
Run
#include<stdio.h> int main () { char name[30]; int i = 0; printf ("Enter a name = "); scanf ("%s", name); while (name[i] != '\0') { printf ("\nThe ascii value of %c = %d", name[i], name[i]); i++; } return 0; }
Output:
Enter a name = Shanvi The ascii value of S = 83 The ascii value of h = 104 The ascii value of a = 97 The ascii value of n = 110 The ascii value of v = 118 The ascii value of i = 105
Example 3:
Run
#include<stdio.h> int main () { int a = 65, b = 97; printf ("Alphabets with their ascii value :\n"); for (int i = 0; i <= 25; i++) { printf ("%c : %d\n", a + i, a + i); } for (int i = 0; i <= 25; i++) { printf ("%c : %d\n", b + i, b + i); } return 0; }
Output:
Alphabets with their ascii value : A : 65 B : 66 C : 67 D : 68 E : 69 F : 70 G : 71 H : 72 I : 73 J : 74 K : 75 L : 76 M : 77 N : 78 O : 79 P : 80 Q : 81 R : 82 S : 83 T : 84 U : 85 V : 86 W : 87 X : 88 Y : 89 Z : 90 a : 97 b : 98 c : 99 d : 100 e : 101 f : 102 g : 103 h : 104 i : 105 j : 106 k : 107 l : 108 m : 109 n : 110 o : 111 p : 112 q : 113 r : 114 s : 115 t : 116 u : 117 v : 118 w : 119 x : 120 y : 121 z : 122
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment