fomat说明符的数量可以少于printf语句中变量的数量吗 [英] can there be less number of fomat specifier than the number of variables in a printf statement

查看:159
本文介绍了fomat说明符的数量可以少于printf语句中变量的数量吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在borland c编译器中编写了以下程序.我的疑问是为什么c编译器在编译时或运行时都不会抛出任何错误.该程序执行正常,输出为2 4.

I have coded the following program in a borland c compiler.My doubt is why c compiler doesnot throw any error neither in compile time or run time.The program executes fine and the output is 2 4.

#include<stdio.h>
#include<conio.h>
int main(){
int a=2,b=4,c=6;
printf("%d%d",a,b,c);
getch();
return 0;
}

即使格式说明符的数目少于参数的数目,也不会引发错误.这里发生了什么.

Even though there are less no of format specifiers than the number of arguments there is no error thrown.What is happening here.

推荐答案

fomat指定符的数量是否少于printf语句中变量的数量

can there be less number of fomat specifier than the number of variables in a printf statement

答案是肯定的.根据C标准:

Answer is yes. From the C Standard:

(c99,7.19.6.1p2)如果在保留参数的情况下用尽了格式,则会(一如既往)对多余的参数进行求值,否则将被忽略."

(c99, 7.19.6.1p2) "If the format is exhausted while arguments remain, the excess arguments are evaluated (as always) but are otherwise ignored."

这篇关于fomat说明符的数量可以少于printf语句中变量的数量吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆