How do I print a char and its equivalent ASCII value in C?
In C programming, a character variable holds ASCII value (an integer number between 0 and 127) rather than that character itself. This integer value is the ASCII code of the character. For example, the ASCII value of 'A' is 65.
Below are the implementation of both methods: Using ASCII values: ASCII value of uppercase alphabets – 65 to 90. ASCII value of lowercase alphabets – 97 to 122.
This prints out all ASCII values:
int main() { int i; i=0; do { printf("%d %c \n",i,i); i++; } while(i<=255); return 0; }
and this prints out the ASCII value for a given character:
int main() { int e; char ch; clrscr(); printf("\n Enter a character : "); scanf("%c",&ch); e=ch; printf("\n The ASCII value of the character is : %d",e); getch(); return 0; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With