C ASCII Value
The ASCII value of a character in C can be obtained using the following syntax:
int ascii_value = character;
where character
is the character for which the ASCII value needs to be obtained, and ascii_value
is an integer variable used to store the ASCII value.
Example
#include <stdio.h>
int main() {
char letter = 'A';
int ascii_value = letter;
printf("The ASCII value of %c is %d\n", letter, ascii_value);
return 0;
}
Output
The ASCII value of A is 65
Explanation
ASCII stands for American Standard Code for Information Interchange. It is a standardized character encoding scheme that assigns unique values to letters, digits, and other special characters. In C, each character has a unique ASCII value associated with it. The ASCII value of a character is an integer that represents its equivalent in the ASCII table.
Use
The ASCII value of a character can be used in various operations, such as comparing characters, sorting strings, and converting characters to their integer equivalent.
Important Points
- The ASCII value of a character is an integer that represents its equivalent in the ASCII table.
- The ASCII value of uppercase alphabets ranges from 65 to 90, and that of lowercase alphabets ranges from 97 to 122.
- The ASCII value of digits 0 to 9 ranges from 48 to 57.
- The ASCII value of special characters such as punctuation marks and whitespace characters varies.
Summary
In C, the ASCII value of a character is a unique integer that represents its equivalent in the ASCII table. Understanding the concept of ASCII values is important for performing various operations on characters in C.