这是我使用指针的第一个任务... 我需要创建一个函数来找出两个数字中哪个更大,而不是替换它们以获得更大的值并打印它们。
我在 main()
的 prinf
中遇到错误:
argument type 'void' is incomplete
我的代码是:
#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!!");
}
最佳答案
larger_of
是一个不返回任何内容的函数。你不能打印它的返回值。
要在调用 larger_of
后打印您的号码,只需执行以下操作:
larger_of(&num1, &num2);
printf("now: %lf and %lf", num1, num2);
关于c - 使用指针替换值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14715159/