C Program to ASCII value of a Character
Introduction:
ASCII stands for American Standard Code for Information Interchange. It is a character encoding standard that represents text in computers and communication equipment. ASCII uses a unique numerical value to represent each character, including letters, digits, punctuation marks, and control characters. The ASCII standard defines 128 characters, which are represented using seven bits, making it a 7-bit character set.
Explanation:
In the ASCII table, each character is assigned a unique decimal number. For example, the ASCII value for the uppercase letter ‘A’ is 65, and for the lowercase letter ‘a’ is 97. The ASCII values for digits range from 48 to 57, and special characters have their own assigned values.
Here’s a simple C program to find the ASCII value of a character:
#include <stdio.h> int main() { char ch; printf("Enter the character"); scanf("%c",&ch); printf("ASCII value of %c=%d",ch,ch); return 0; }
In this program:
- We declare a variable
ch
of typechar
to store the input character. - The
printf
statement prompts the user to enter a character. - The
scanf
statement reads the character from the user. - The
printf
statement then prints the ASCII value of the entered character.
Output:
Enter the character O ASCII value of O=79
Conclusion:
Understanding ASCII values is crucial in computer programming, especially when dealing with character-based operations and communication. ASCII values enable computers to represent and process textual information in a standardized way. The C program provided demonstrates a simple way to find the ASCII value of a character, showcasing the fundamental relationship between characters and their corresponding numeric representations in the ASCII table.