C中的隐式转换? [英] Implicit conversion in C?

查看:82
本文介绍了C中的隐式转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是怎么回事:

printf("result = %d\n", 1);
printf("result = %f\n", 1);

输出:

result = 1
result = 0.000000

如果在尝试打印它们之前确保这些变量的类型,那么它当然可以正常工作.为什么第二个打印语句没有隐式转换为1.00000?

If I ensure the type of these variables before trying to print them, it works fine of course. Why is the second print statement not getting implicitly converted to 1.00000?

推荐答案

在第二种情况下,格式字符串和参数类型不匹配-因此结果是不确定的行为.

In the second case you have a mismatch between your format string and the argument type - the result is therefore undefined behavio(u)r.

这篇关于C中的隐式转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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