C Program to Find ASCII Value of Character

In this article, we are going to learn how to Find the ASCII Value of a Character. In computer science, we have ASCII format that has a unique representation of all characters and numbers. In this program, we will try to find the ASCII value which is associated with each character.

C Program to Find ASCII Value of character


In this example, we are going to learn how to find the ASCII value of a character. We will ask the user to enter a character input. We will take this input value and will try to find the ASCII value of this character. In C language, we can use the %d format specifier to find the ASCII value. When we take input from the user we will take input as %c and when we try to print this character by using %d then we will get its ASCII value.

#include <stdio.h>
int main() 
{  
    char ch;
    printf("Please enter a character: ");
    scanf("%c", &ch);  
    
    printf("The ASCII value of %c = %d", ch, ch);
    
    return 0;
}

Output

Please enter a character: y
The ASCII value of y = 121

1. C Program to Find ASCII Values for all characters


The ASCII value of characters Falls in the range of 65 to 122. Where 65 represents the upper case character A and 90 characters Z.To find out all character ASCII values run we have to run a loop starting for 65 till 122.

  • The range from 65 to 90 is for upper case letters: A to Z.
  • The range from 91 to 96 is the ASCII value of a special character
  • The range from 97 to 122 is for lower case letters: a to z.

C Program to Find ASCII Values for all characters

#include <stdio.h>
int main() {
  
   int val = 0;
   printf("All Character \t ASCII Value\n\n");
   
   for (val = 65; val <=122; val++) {
      printf("%c = %d\n", val, val);

   }
   return 0;
}

Output

All 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
[ = 91
\ = 92
] = 93
^ = 94
_ = 95
` = 96
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