这个程序的第7行“pay=prt(pay);”不是应该抛出编译或运行时错误,因为它将in t传递给需要double的参数吗?我用dev-c++很好地编译了它,并用两行输出运行了程序请解释一下,谢谢。

#include <stdio.h>
int prt(double b);
main ()
{
    int pay = 3;
    double tax = 2.2;
    pay = prt(pay);
    prt(tax);
}

int prt(double b)
{
    b *= 2;
    printf("%.2lf\n", b);
}

最佳答案

在这种情况下,C将在不同的数值类型之间自动转换。
Implicit type conversion in C-like languages

08-16 00:05