// width.cpp : 定义控制台应用程序的入口点。 // /* width.c -- 字段宽度 */ /* 时间:2018年06月15日 23:43:01 代码:程序清单4.7_width.c程序_《C Primer Plus》P71 目的:了解 printf() %d d前加参数的输出结果 */ #include "stdafx.h" #define PAGES 931 int _tmain(int argc, _TCHAR* argv[]) { printf("*%d*\n", PAGES); printf("*%2d*\n", PAGES); printf("*%10d*\n", PAGES); printf("*%-10d*\n", PAGES); getchar(); return 0; } /* 在VS2010中运行结果: -------------------------------------------------------- *931* *931* * 931* *931 * -------------------------------------------------------- 总结: 1>.%2d 当参数大于2时,则显示参数的真实位数; 2>.%10d 显示10位靠右的数字,左则无数则以空格符替代; 3>.%-10d 显示10位靠左的数字,右则无数则以空格符替代; -------------------------------------------------------- */
程序清单4.7_width.c程序_《C Primer Plus》P71
原创
©著作权归作者所有:来自51CTO博客作者广西梵音的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章