许多参数的printf错误导致奇怪的结果 [英] Wrong number of parameters to printf leads to strange results

查看:184
本文介绍了许多参数的printf错误导致奇怪的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>

int main() {
   int i=10,j=20;
   printf("%d%d%d",i,j);
   printf("%d",i,j); 
   return 0;
}

使用的Turbo C编译器,输出是这样的:

Using the Turbo C compiler, the output is like:


10 10 garbageValue

20

有人能解释这是为什么?

Can someone explain why this is?

推荐答案

您所使用的编译器?我测试的Turbo C 2.0和Turbo C ++ V 4.5编译器和输出

Which compiler you are using? I tested it on turbo c v2.0 and turbo c++ v 4.5 compilers and the output is

10 20 garbage value

10 

这是实际的输出只使用两个变量和三个格式说明你会得到。因此,将打印存储在两个变量中的值,并打印一个垃圾值

This is the actual output you will get as you are using only two variables and three format specifiers. So it will print the values stored in the two variables and print a garbage value.

在第二种情况下使用的是只有一个格式指示符和两个变量,因此在这种情况下,它将只打印存储在变量的一个值,并跳过其他变量。如果你编译它下的Turbo C 2.0和Turbo C ++编译器4.5你可能会得到上面的输出。

In the second case you are using only one format specifier and two variables, so in that case it will only print one value stored in the variable and skips the other variable. You might get the above output if you compile it under turbo c 2.0 and turbo c++ 4.5 compilers.

这篇关于许多参数的printf错误导致奇怪的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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