int如何将类型提升为char? [英] How does an int gets type promoted to a char ?
本文介绍了int如何将类型提升为char?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
展开 | 选择 | Wrap | 行号
解决方案
你应该做的第一件事就是搞错了
展开 | 选择 | Wrap | 行号
没有促销到char的东西。
促销意味着将较小的类型变为更大的类型。就像将char(1个字节)提升为int(4个字节)一样。
%c和%d是printf格式说明符,您可以在其中请求将数据显示为char或作为一个int。
在这种情况下,数组的int由printf强制转换为char。很可能int的最低有效字节(LSB)成为char。 int的剩余字节都会丢失。
这就是我想说的0,2,3这些数字是4字节值,因此这些将被转换从LSB开始到1个字节,因此对于arr [1] = 2,op必须是与ascii值2对应的某个字符,但它不打印任何内容,虽然它为ascii值3和4输出了一些字符,那么呢? / BLOCKQUOTE>
Expand|Select|Wrap|Line Numbers解决方案First thing you should do is get the errors out
Expand|Select|Wrap|Line Numbers
There is no such thing as promotion to a char.
Promotion means to make a smaller type into a bigger type. Like promotion a char (1 byte) to an int (4 bytes).
The %c and %d are printf format specifiers where you request the data to be displayed as a char or as an int.
In this case the int of the array is typecast by printf to a char. Most likely the least significant byte (LSB) of the int becomes the char. The remaining bytes of the int are lost.
So that''s what I am trying to say that 0 , 2,3 these numbers are 4 byte value , hence these would be getting converted to 1 byte starting from LSB , so for arr[1]= 2 , op must be some character corresponding to ascii value 2 , but it is not printing anything , although it prints some character for ascii value 3 and 4 , so then ?
这篇关于int如何将类型提升为char?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆