Lesson10 PoEdu培训第二课 C语言篇(2) 整数类型 随堂作业
文章类别: 培训作业 0 评论

Lesson10 PoEdu培训第二课 C语言篇(2) 整数类型 随堂作业

文章类别: 培训作业 0 评论

老师未批改

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;
}

程序运行截图如下:
Alt 运行结果1

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;
}

程序运行截图如下:

Alt 运行结果2

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;
}

程序运行截图如下:

Alt 运行结果3

如有错误,请提出指正!谢谢.

回复