用%f占位符输出整形变量的问题

 时间:2024-10-15 12:23:12

1、下文是C11标准的文档:坡纠课柩if type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior is undefined, except for the following cases:— one type is a signed integer type, the other type is the corresponding unsigned integer type, and the value is representable in both types;— one type is pointer to void and the other is a pointer to a character type.由此我们可以知道,用类型不匹配的占位符格式化输出一个变量的行为是未定义的(int类型与unsigned int类型以及指向void类型的指针类型和指向字符型的指针类型除外),下面我们就来分析这种未定义的行为

2、我们都知道(如果不知道请参阅《深入理解计算机系统》第二章),int类型的变量是在计算机中是以补码形式存储的,以十进制数字10为例,在计算机中它的存储形式应当为00000000 00000000 00000000 00001010,然而,单精度浮点数的存储形式为第一位表示该数字的符号,随后的8位标识其指数部分,剩下的23位表示其尾数部分,所以,当以补码形式存储的十进制整形数字10被以单精度浮点型解释的时候,它就变成了+1*10^(-20)+1*10^(-22),这个数字非常接近于0,而单精度浮点型的尾数部分默认为6位,将该数值的精度设定为小数点后六位的时候,它的数值就变成0了。

  • 正交矩阵一定可逆吗
  • 几何重数和代数重数是什么
  • 多元函数的几种极限求法
  • 小蜜蜂智慧服务中心怎么取件
  • 球壳的转动惯量是什么
  • 热门搜索
    法制手抄报 平安校园手抄报 爱国手抄报 植树节手抄报简单好看 防溺水安全手抄报 春分手抄报 端午节手抄报 感恩手抄报 关于六一儿童节的手抄报 端午节手抄报内容