ASCII Value of a Character in C
Last Updated :
08 Feb, 2024
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.
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
#include <stdio.h>
int main()
{
char c = 'k' ;
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.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...