ASCII stands for American Standard Code for Information Interchange, which is a standardized encoding system used to represent text characters in computers. Each ASCII character is assigned a unique numeric value between 0 and 127.
What are ASCII Values?
ASCII values, also known as ASCII codes or ASCII character codes, are a standardized set of numeric values used to represent characters in computers. ASCII stands for American Standard Code for Information Interchange and was developed in the 1960s as a way to standardize the representation of characters used in electronic communication.
In the ASCII encoding system, each character is assigned a unique numeric value between 0 and 127. For example, the ASCII value of the letter ‘A’ is 65, the ASCII value of the digit ‘0’ is 48, and the ASCII value of the space character is 32.
ASCII values are used extensively in computer programming to represent text characters. For example, when a user types a letter on a keyboard, the corresponding ASCII value of that letter is sent to the computer and processed as data. Similarly, when a computer program outputs text to a screen or printer, it uses ASCII values to represent the characters.
In addition to the standard ASCII encoding, there are also extended ASCII encodings that include additional characters beyond the 128 standard ASCII characters. These extended ASCII encodings are used in different countries and regions to support additional character sets, such as accented letters and special symbols.
Overall, ASCII values are a fundamental aspect of text encoding in computers and are used extensively in computer programming, data processing, and electronic communication.
In C programming, you can find the ASCII value of a character using the built-in function int printf(const char *format, ...)
. Here is how you can do it:
1 | #include <stdio.h> |
1 | char c = 'A'; |
1 | printf("The ASCII value of %c is %d\n", c, c); |
The output will be:
1 | The ASCII value of A is 65 |
Here, the %c
the format specifier is used to print the character value and the %d the format specifier is used to print the integer value of the character.
If you want to find the ASCII values of multiple characters, you can use a loop to iterate through the characters and print their ASCII values. Here’s an example:
1 2 3 4 5 6 7 8 9 10 11 12 | #include <stdio.h> #include <stdio.h> int main() { char str[] = "Ebhor.com"; int i; for(i = 0; str[i] != '\0'; i++) { printf("The ASCII value of %c is %d\n", str[i], str[i]); } return 0; } |
The output will be:
1 2 3 4 5 6 7 8 9 | The ASCII value of E is 69 The ASCII value of b is 98 The ASCII value of h is 104 The ASCII value of o is 111 The ASCII value of r is 114 The ASCII value of . is 46 The ASCII value of c is 99 The ASCII value of o is 111 The ASCII value of m is 109 |
Here, the loop iterates through the characters in the string str
and prints their ASCII values using the printf()
function.
C program to print ASCII values of Capital A to Z
1 2 3 4 5 6 7 8 9 10 | #include <stdio.h> int main() { int i; for(i = 65; i <= 90; i++) { printf("The ASCII value of %c is %d\n", i, i); } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | The ASCII value of A is 65 The ASCII value of B is 66 The ASCII value of C is 67 The ASCII value of D is 68 The ASCII value of E is 69 The ASCII value of F is 70 The ASCII value of G is 71 The ASCII value of H is 72 The ASCII value of I is 73 The ASCII value of J is 74 The ASCII value of K is 75 The ASCII value of L is 76 The ASCII value of M is 77 The ASCII value of N is 78 The ASCII value of O is 79 The ASCII value of P is 80 The ASCII value of Q is 81 The ASCII value of R is 82 The ASCII value of S is 83 The ASCII value of T is 84 The ASCII value of U is 85 The ASCII value of V is 86 The ASCII value of W is 87 The ASCII value of X is 88 The ASCII value of Y is 89 The ASCII value of Z is 90 |
C program to print ASCII values of Smallatoz
1 2 3 4 5 6 7 8 9 10 | #include <stdio.h> int main() { int i; for(i = 97; i <= 122; i++) { printf("The ASCII value of %c is %d\n", i, i); } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | The ASCII value of a is 97 The ASCII value of b is 98 The ASCII value of c is 99 The ASCII value of d is 100 The ASCII value of e is 101 The ASCII value of f is 102 The ASCII value of g is 103 The ASCII value of h is 104 The ASCII value of i is 105 The ASCII value of j is 106 The ASCII value of k is 107 The ASCII value of l is 108 The ASCII value of m is 109 The ASCII value of n is 110 The ASCII value of o is 111 The ASCII value of p is 112 The ASCII value of q is 113 The ASCII value of r is 114 The ASCII value of s is 115 The ASCII value of t is 116 The ASCII value of u is 117 The ASCII value of v is 118 The ASCII value of w is 119 The ASCII value of x is 120 The ASCII value of y is 121 The ASCII value of z is 122 |
C program to print ASCII values of 0 to 9
1 2 3 4 5 6 7 8 9 10 | #include <stdio.h> int main() { int i; for(i = 48; i <= 57; i++) { printf("The ASCII value of %c is %d\n", i, i); } return 0; } |
1 2 3 4 5 6 7 8 9 10 | The ASCII value of 0 is 48 The ASCII value of 1 is 49 The ASCII value of 2 is 50 The ASCII value of 3 is 51 The ASCII value of 4 is 52 The ASCII value of 5 is 53 The ASCII value of 6 is 54 The ASCII value of 7 is 55 The ASCII value of 8 is 56 The ASCII value of 9 is 57 |
In summary, finding the ASCII value of a character in C is straightforward using the printf()
function and the %d
format specifier. You can also use loops to find the ASCII values of multiple characters.