Possible Duplicate:
Negative ASCII value
int main() {
char b = 8-'3';
printf("%c\n",b);
return 0;
}
I run this program and I get a sign which looks like a question mark (?).
My question to you is why is it prints that and not printing nothing, beacause as far as I know the value of b by the ASCII table is minus 43 which is not exist.
by the way, when I compile this code:
int main() {
char b = -16;
printf("%c\n",b);
return 0;
}
I get nothing.
Here's the behavior as specified in the C 2011 standard
7.21.6.1 The fprintf function
...
8 The conversion specifiers and their meanings are:
...c
If nol
length modifier is present, theint
argument is converted to anunsigned char
, and the resulting character is written.
If anl
length modifier is present, thewint_t
argument is converted as if by anls
conversion specification with no precision and an argument that points to the initial element of a two-element array ofwchar_t
, the first element containing thewint_t
argument to thelc
conversion specification and the second a null wide character.
That -43 is being converted to an unsigned value (213), so it's printing an extended ASCII character.
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