ASCII TABLE - 负值 [英] ASCII TABLE - negative value
本文介绍了ASCII TABLE - 负值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
负数ASCII值
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 (?).
我的问题是,为什么是打印,不打印什么,只要我知道b的值由ASCII表减去43
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:
c $ c> int main(){
char b = -16;
printf(%c \\\
,b);
return 0;
}
int main() {
char b = -16;
printf("%c\n",b);
return 0;
}
我什么都没有。
推荐答案
以下是 C 2011标准
7.21.6.1 fprintf函数
...
8转换规范及其含义如下:
...
c
如果不存在l
长度修改,则int
参数被转换为
unsigned char
,并写入结果字符。
如果存在l
长度修改符,wint_t
参数被转换为
和ls
转换规范,没有精度,参数指向
到wchar_t
的两个元素数组的初始元素,第一个元素
包含wint_t
cc的参数lc
转换规范和
第二个零宽字符。
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.
该-43被转换为无符号值(213),所以它打印一个扩展的ASCII字符。
That -43 is being converted to an unsigned value (213), so it's printing an extended ASCII character.
这篇关于ASCII TABLE - 负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文