老师未批改
1. 使用正确的占位符打印出 int, long, longlong 的最大值和最小值.(有符号)
程序源代码如下:
/*************************************************************************
> 文件名: lesson10.hw01.c
> 作者: 花心胡萝卜
> 邮箱: hxhlb@hxcarrot.com
> 创建时间: 2016-09-09 23:00:03
************************************************************************/
#include <stdio.h>
int main() {
printf("int 类型的最大值为: [%d], 最小值为: [%d]\n", 0x7FFFFFFF, 0x80000000);
printf("long 类型的最大值为: [%ld], 最小值为: [%ld]\n", 0x7FFFFFFF, 0x80000000);
printf("longlong 类型的最大值为: [%lld], 最小值为: [%lld]\n", 0x7FFFFFFFFFFFFFFF, 0x8000000000000000);
return 0;
}程序运行截图如下:
2. 请写出一个16进制数的溢出有符号和无符号的long型.
程序源代码如下:
/*************************************************************************
> 文件名: lesson10.hw02.c
> 作者: 花心胡萝卜
> 邮箱: hxhlb@hxcarrot.com
> 创建时间: 2016-09-09 23:10:19
************************************************************************/
#include <stdio.h>
int main() {
long lHexValue = 0x7FFFFFFF;
unsigned long ulHexValue = 0xFFFFFFFF;
lHexValue += 1;
ulHexValue += 1;
printf("long 类型的值为0x7FFFFFFF的溢出有符号值为: [%d], 无符号值为: [%u]\n", lHexValue, lHexValue);
printf("unsigned long 类型的值为0xFFFFFFFF的溢出有符号值为: [%d], 无符号值为: [%u]\n", ulHexValue, ulHexValue);
return 0;
}程序运行截图如下:

3. -12345在无符号 int 中值为多少?
程序源代码如下:
/*************************************************************************
> 文件名: lesson10.hw03.c
> 作者: 花心胡萝卜
> 邮箱: hxhlb@hxcarrot.com
> 创建时间: 2016-09-09 23:15:59
************************************************************************/
#include <stdio.h>
int main() {
int iValue = -12345;
printf("int 类型的值为 [%d] 的16进制值为: [%0X]\n", iValue, iValue);
printf("int 类型的值为 [%d] 的无符号值为: [%u]\n", iValue, iValue);
return 0;
}程序运行截图如下:

如有错误,请提出指正!谢谢.
本文由 花心胡萝卜 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: 2016-10-06 at 03:12 pm
