程序清单3.4_print2.c程序_《C Primer Plus》P41

// print2.cpp : 定义控制台应用程序的入口点。
//
/* print2.c -- printf()的更多属性 */

/*
    时间:2018年06月04日 23:49:04
    代码:程序清单3.4_print2.c程序_《C Primer Plus》P41
    目的:不同的数据类型要匹配不同的输出控制符(即书中说的:说明符)
*/
#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
        unsigned int un = 3000000000;    /* int 为 32 位 */
    short end = 200;                /* 和 short 为 16 位的系统 */
    long big = 65537;
    long long verybig = 12345678908642;

    printf("un = %u and not %d\n", un, un);
    printf("end = %hd and %d\n", end, end);
    printf("big = %ld and not %hd\n", big, big);
    printf("verybig = %lld and not %ld\n", verybig, verybig);

    getchar();

    return 0;
}

/*
    在VS2010中运行结果:
----------------------------------------------
un = 3000000000 and not -1294967296
end = 200 and 200
big = 65537 and not 1
verybig = 12345678908642 and not 1942899938
----------------------------------------------
    总结:
    如果使用了不正确的输出控制符(即:说明符),会造成
意想不到的后果。目前要做的就是好好匹配说明符,别搞错了!
----------------------------------------------
*/


猜你喜欢

转载自blog.51cto.com/13555061/2124836
今日推荐