C programming language uses ASCII codes to represent characters. ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns unique numeric codes to each character. In this article, we will discuss ASCII values in C programming language, their usage, and examples.
An ASCII value is a unique numeric code assigned to each character in the ASCII character set
What are ASCII Values?
An ASCII value is a unique numeric code assigned to each character in the ASCII character set. ASCII values are used to represent characters in C programming language. For example, the ASCII value for the letter ‘A’ is 65, and the ASCII value for the letter ‘a’ is 97.
Using ASCII Values in C Programming:
In C programming language, we can use ASCII values to perform various operations on characters. Here are some common examples of using ASCII values in C programming:
Converting characters to their ASCII values
Converting ASCII values to characters
Performing arithmetic operations on ASCII values
Examples of ASCII Values:
Here are some examples of using ASCII values in C programming language:
Example 1: Converting characters to their ASCII values
// Converting a character to its ASCII valuechar c = 'A';int ascii_value = c;// Printing the ASCII value of the characterprintf("The ASCII value of %c is %d", c, ascii_value);
Output:
The ASCII value of A is 65
Example 2: Converting ASCII values to characters
// Converting an ASCII value to its characterint ascii_value = 65;char c = ascii_value;// Printing the character corresponding to the ASCII valueprintf("The character corresponding to the ASCII value %d is %c", ascii_value, c);
Output:
The character corresponding to the ASCII value 65 is A
Example 3: Performing arithmetic operations on ASCII values
// Performing arithmetic operations on ASCII valueschar c1 = 'A';char c2 = 'B';int ascii_value1 = c1;int ascii_value2 = c2;int sum = ascii_value1 + ascii_value2;// Printing the sum of ASCII valuesprintf("The sum of the ASCII values of %c and %c is %d", c1, c2, sum);
Output:
The sum of the ASCII values of A and B is 131.
Conclusion:
ASCII values are an essential part of C programming language, and they are used to represent characters in a program. In this article, we discussed the usage of ASCII values in C programming language and provided examples of their usage. Understanding ASCII values is essential for any programmer who wants to work with characters in C programming language.
0 Comments