SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C program to print the ascii value of a character
C program to print the ascii value of a character
Input:
Enter a character to print its ASCII value:
a
Output:
The ASCII value of a is 97
Implementation:
/* ASCII - American Standard Code for Information Interchange ASCII values of some of the characters are: CHARACTER ASCII Value -------------------------------- NULL 0 Space 32 ! 33 " 34 # 35 $ 36 % 37 0 to 9 48 to 57 A to Z 65 to 90 a to z 97 to 122 Here, to print the ASCII value of a character entered can be found by: 1. Getting a character from the user in a character variable 2. Printing the character using "%d" format specifier What happens is , the character is pushed / forced to typecast into integer which gives us the ASCII value of that character. */ #include
int main(void) { /* Character variable to accept a character from the user */ char ch; printf("Enter a character to print its ASCII value:\n"); scanf("%c",&ch); /* Forcing the character to get typecasted into integer value, thereby resulting in printing the ASCII value of the character entered */ printf("The ASCII value of %c is %d",ch,ch); return 0; }
PREVIOUS
NEXT
HOME