C Program To Print ASCII Value of a Character
We use a format specifier here to give the numeric value of the character. Here %d is used to convert a character to its ASCII value.
C
// C program to print // ASCII Value of Character #include <stdio.h> // Driver code int main() { char c = 'k' ; // %d displays the integer value of // a character // %c displays the actual character printf ( "The ASCII value of %c is %d" , c, c); return 0; } |
Output
The ASCII value of k is 107
Complexity Analysis
- Time complexity: O(1)
- Auxiliary Space: O(1)
Refer to the complete article Program to print ASCII Value of a character for more methods to print the ASCII value of a character.
ASCII Value of a Character in C
American Standard Code for Information Interchange (ASCII) is a character encoding standard that assigns a unique numerical value to all characters including special symbols. In C programming, the ASCII value of the character is stored instead of the character itself. For example, the ASCII value of ‘A’ is 65.
- Each character or special character is represented by some ASCII code.
- Each ASCII code occupies 7 bits in memory.
- Each character variable is assigned an ASCII value ranging from 0 to 127.
In this article, we will learn how to find and print the ASCII value of the character in C.
Contact Us