pow(1,0)返回0? [英] pow(1,0) returns 0?

查看:611
本文介绍了pow(1,0)返回0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这样做:

printf("%d\n", pow(1,0)); /* outputs 0 */

返回0?我希望它返回1.

推荐答案

pow() 返回类型.您需要使用%f格式说明符来打印double.

pow() returns a double type. You need to use %f format specifier to print a double.

为提供的参数类型使用不合适的格式说明符会导致不确定的行为.检查C标准N1570(C11)的第7.2.1.6.1节. (是的,这没有专门针对C89,恕我直言)

Using inappropriate format specifier for the supplied argument type causes undefined behaviour. Check chapter §7.21.6.1 of the C standard N1570 (C11). (Yes, this has nothing specific to C89, IMHO)

这篇关于pow(1,0)返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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