使用printf函数 [英] use of printf function

查看:86
本文介绍了使用printf函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行这段代码

I am running this code

int i=5;
printf("%d %d",i)


给输出5 5
为什么给出此输出.
当我们运行


give output 5 5
why it give this output.
when we run

int i=5;
printf("%d %d %d",i)


给输出5 5 0

为什么?


Give output 5 5 0

Why?

推荐答案

好运. printf()函数通过格式字符串起作用,并为每个变量标识符选择堆栈上的下一个参数.如果变量少于标识符,那么您将获得最好的随机值,最坏的程序崩溃.在您的情况下,值恰好是相同的,因此不能保证.
Just luck. The printf() function works its way through the format string and for each variable identifier it selects the next argument on the stack. If you have fewer variables than identifiers then you will get, at best random values, at worst program crashes. In your case the values just happen to be the same, it is not guaranteed.


这篇关于使用printf函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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