How to get Ascii value of char in C?
I assume you know when we assign lower sized data type to a higher sized data type it will automatically convert it to higher sized data type.
So, when we assign char to int. It will convert char to its ASCII, which is an int. Hence we get ASCII value of char.
Checkout the below code :
#include <stdio.h>
int main()
{
char ch = 'A';
int i = ch;
printf("Ascii value of %c is %d \n",ch,i);
return 0;
}
Internally,
int i = ch;
Will be converted to :
int i = (int)ch
Output :
Ascii value of A is 65

0 Comments