#include<stdio.h>
int main() {
int i = 3771717;
printf ("%c", i);
return 0;
}
The output is E
. Isn't 69 the ASCII for E
?
#include<stdio.h>
int main() {
int i = 3771717;
printf ("%c", i);
return 0;
}
The output is E
. Isn't 69 the ASCII for E
?
The %c
format specifier expects an int
argument which is then converted to and unsigned char
as printed as a character.
The int
value 3771717 gets converted to the unsigned char
value 69 as per the conversion rules from a signed integer to unsigned integer. The C standard specifies this is done by repeatedly subtracting one more than the maximum value for unsigned char
until it is in range. In practice, that means truncating the value to the low order byte. 3771717 decimal is 398D45 hex so that leaves us with 45 hex which is 69 decimal.
Then the character code for 69 i.e. 'E'
is printed.