In this post, you will get to know how to find ASCII Value of any character in the C Programming language.
![C Program To Find ASCII Value of a Character](https://www.codingbroz.com/wp-content/uploads/2021/08/c-program-to-find-ascii-value-of-a-character-codingbroz.png)
ASCII Value represents the English Characters as numbers, each letter is assigned a number from 0 to 127. For example, The ASCII Value of N is 78.
So, Without Further Ado, let’s begin the tutorial.
C Program To Find ASCII Value of a Character
// C Program To Find ASCII Value of a Character #include <stdio.h> int main(){ char a; // Asking for the Input printf("Enter the String: "); scanf("%c", &a); // Displays Output printf("ASCII Value of %c = %d", a, a); return 0; }
Output
Enter the String: N
ASCII Value of N = 78
How Does This Program Work ?
char a;
In the above example, we have declared a string data type variable named a.
// Asking for the Input
printf("Enter the String: ");
scanf("%c", &a);
Then, the user is asked to enter a character, the character is stored in the variable a.
// Displays Output
printf("ASCII Value of %c = %d", a, a);
Finally, the ASCII Value of the character is displayed using %d. %c is used to display the String data type.
Some Used terms as follow:
#include <stdio.h> – In the first line we have used #include, it is a preprocessor command that tells the compiler to include the contents of the stdio.h(standard input and output) file in the program.
The stdio.h is a file which contains input and output functions like scanf() and printf() to take input and display output respectively.
Int main() – Here main() is the function name and int is the return type of this function. The Execution of any Programming written in C language begins with main() function.
scanf() – scanf() function is used to take input from the user. Here %c indicates that we are reading String Data Type.
printf() – printf() function is used to display and print the string under the quotation to the screen.
// – Used for Commenting in C
C Program To Find ASCII Value of all Characters
// C Program To Print ASCII Value of all Characters #include <stdio.h> int main(){ int i; for (i = 0; i < 26; i++){ printf("%c = %d | %c = %d \n", 'A'+i, 'A'+i, 'a'+i, 'a'+i); } return 0; }
Output
A = 65 | a = 97
B = 66 | b = 98
C = 67 | c = 99
D = 68 | d = 100
E = 69 | e = 101
F = 70 | f = 102
G = 71 | g = 103
H = 72 | h = 104
I = 73 | i = 105
J = 74 | j = 106
K = 75 | k = 107
L = 76 | l = 108
M = 77 | m = 109
N = 78 | n = 110
O = 79 | o = 111
P = 80 | p = 112
Q = 81 | q = 113
R = 82 | r = 114
S = 83 | s = 115
T = 84 | t = 116
U = 85 | u = 117
V = 86 | v = 118
W = 87 | w = 119
X = 88 | x = 120
Y = 89 | y = 121
Z = 90 | z = 122
Conclusion
I hope after going through this tutorial, you have understood how to find ASCII Value of any Character in C Programming language.
If you still have any doubt regarding this, feel free to contact us in the Comment Section. We will be delighted to help you.