正在加载图片...
3整型数据的溢出 整型≠整数 int的范围:-32768~+32767 Example: 运行结果: include <stdio. h> include <conio.h> nput:12345 a=12345 Why maino nput:1234567 ? int a j a=-10617 Because:12345的补码是 0011000000111001 1234567的补码是100101101011010000111 截去多余部份(超过2个字节的左边部分)后 其原码为 1010100101111001(-10617) 参见教材P44整型数据的溢出”。3.整型数据的溢出 • 整型≠整数 int 的范围: - 32768~+32767 Example: #include <stdio.h> #include <conio.h> main() { int a ; printf(“Input :”); scanf(“%d”,&a); printf(“a=%d\n”,a); } 运行结果: Input:12345 a=12345 Input:1234567 a= -10617 Why ?! Because: 12345的补码是 0011000000111001 1234567的补码是 100101101011010000111 截去多余部份(超过2个字节的左边部分)后 其原码为 1010100101111001(-10617) 参见教材P44“整型数据的溢出
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有