我是 C 编程的新手,但在 Java 方面还不错,我的问题是我们什么时候使用 %d 和 %f?在什么情况下?例如,根据下面给出的代码块,如果我被要求取 (int)a*(float)y,我是将它作为 %d 还是作为 %f?
#include <stdio.h>
int main()
{
int a = 2;
float y= 1.5;
printf("%d \n", a*y); //do I take this?
printf("%f", a*y); //do I take this?
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
745417384
3.000000