1

这是我使用指针的第一个任务......我需要创建一个函数来找出两个数字中的哪一个更大,然后替换它们以获得更大的值并打印它们。

我在以下prinf内容中遇到错误main()

参数类型“void”不完整

我的代码是:

#include <stdio.h>
void larger_of(double * x, double * y);

int main()

{
    double num1 = 4.5;
    double num2 = 5.5;

    printf("the original two numbers is %.1lf and %.1lf\n", num1, num2);
    printf("now: %lf and %lf", larger_of(&num1, &num2));

}

void larger_of(double * x, double * y)

{
    if (* x > * y)
        * y = * x;
    else if
       (* x < * y)
        * x = * y;
    else
        printf("they are equale!!");
}
4

2 回答 2

5

larger_of是一个不返回任何内容的函数。你不能打印它的返回值。

要在通话后打印您的号码,larger_of只需执行以下操作:

larger_of(&num1, &num2);
printf("now: %lf and %lf", num1, num2);
于 2013-02-05T19:19:01.777 回答
4

您正在尝试打印 void

printf("now: %lf and %lf", larger_of(&num1, &num2));

你必须做什么:

larger_of(&num1, &num2)
printf("now: %lf and %lf",num1,num2);
于 2013-02-05T19:19:46.317 回答