当我尝试打印幂函数的结果,我总是得到0 [英] When I try to print result of the power function I always get 0
本文介绍了当我尝试打印幂函数的结果,我总是得到0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用C begginner,当我尝试写一些code这样的:
I am begginner in C and when I try to write some code like that :
printf("\n Answer : %d \n", 12* pow(2,1));
我总是回答:0
但是,当我写的是这样的浮点数字:
I always get Answer : 0 But when I write as a float point number like this :
printf("\n Answer : %f \n", 12* pow(2,1));
我得到:答:24.0000
I get : Answer : 24.0000
有没有人知道为什么会发生这种情况?
我的意思是,为什么0十进制印刷?
非常感谢。
Is there anyone know why this is happening ? I mean why 0 in decimal printing ? Thank you so much.
推荐答案
你看到的是未定义行为的结果
的printf 按期望的类型,并通过不匹配的类型。
The type expected by printf
and the type passed do not match.
的说明%D
必须键入 INT
的值相匹配,但匹配类型的值双击
你提供你的前任pression。
The specifier "%d"
must match a value of type int
, but matches a value of type double
you provided with your expression.
任何事情都有可能发生。
Anything can happen.
这篇关于当我尝试打印幂函数的结果,我总是得到0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文