什么是printf函数的返回类型 [英] what is the return type of printf

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

问题描述

这可能是愚蠢的问题,但我很困惑。这就是为什么我清理我的怀疑。昨天,我的采访中我有一个问题,像

It may be stupid question, but i'm confused. That's why i'm clearing my doubt. yesterday, during my interview i got one question like

char ch="Hello";
printf("%d",printf("%s",ch));

我觉得的printf 无效类型的功能,因为我从来没有见过的printf 功能分配给任何变量。所以,我告诉,它会显示的编译错误。因为,编译器将无法找到返回类型的printf 功能。可是,我错了。而输出的 Hello5 。我真的很迷惑,如何来了。

I thought printf is a void type function, because i never seen printf function to assign to any variable. So, i told, it will show compile error. Since, compiler won't find return type printf function. But, i was wrong. And the output is Hello5. I'm really confuse, how this comes.

推荐答案

该函数fun()将返回一个int,你只是没有将其分配到任何东西。因此,它没有分配到任何东西的返回值被丢弃。

The function fun() is returning an int, you are just not assigning it to anything. So the return value is being discarded as it is not assigned to anything.

的printf的方式,是不是一个空函数但返回打印字符的数量,这是5的你好的情况下。

printf by the way, is not a void function but returns the number of characters printed, which is 5 in case of "Hello".

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

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