我在 borland c 编译器中编写了以下程序。我的疑问是为什么 c 编译器在编译时或运行时都不会抛出任何错误。程序执行正常,输出为 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;
}
即使格式说明符的数量少于参数的数量,也不会抛出错误。这里发生了什么。
最佳答案
can there be less number of fomat specifier than the number of variables in a printf statement
答案是肯定的。来自 C 标准:
(c99, 7.19.6.1p2) "If the format is exhausted while arguments remain, the excess arguments are evaluated (as always) but are otherwise ignored."
关于格式说明符的数量是否可以少于 printf 语句中变量的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21659175/