格式说明符的数量是否可以少于 printf 语句中变量的数量

标签 c format format-specifiers

我在 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/

相关文章:

c - 段错误从函数返回字符串数组

c - %.#s 在 c 中的 printf 语句中的格式说明符

c - c中的格式说明符值问题

eclipse - 如何在同一行上设置空大括号的格式(Eclipse 格式化程序)

android - 更改 ACTION_VIDEO_CAPTURE 的格式

c++ - 获取类型的打印说明符的惯用方法?

c - 这个语法在 C 中是什么意思?变量 = (arg0 + arg1 == arg2 ? 0x1 : 0x0) & 0xff;

c - 用 C 语言从 child 向 parent 发送信号。 "User defined signal 1: 30"

从 FORTRAN 调用 C 代码

java - java中的日期只有年份