Function 无效的二进制操作数,缺少理论

Function 无效的二进制操作数,缺少理论,function,pointers,int,syntax-error,main,Function,Pointers,Int,Syntax Error,Main,我收到一个错误“二进制*的操作数无效(具有'double'和'double*)” 虽然x,y的变量是正常的双精度变量,但我必须使用函数作为它的指针,所以我发送了它们的地址,以使函数工作。我不明白为什么斜率没有误差,只有*y_截距 void determine_line(double *, double *, double *, double *, double *, double *); int main() { double x1 = 0.0, x2 = 0.0, y1 = 0.0,

我收到一个错误“二进制*的操作数无效(具有'double'和'double*)” 虽然x,y的变量是正常的双精度变量,但我必须使用函数作为它的指针,所以我发送了它们的地址,以使函数工作。我不明白为什么斜率没有误差,只有*y_截距

void determine_line(double *, double *, double *, double *, double *, double *);

int main()
{
    double x1 = 0.0, x2 = 0.0, y1 = 0.0, y2 = 0.0, m = 0.0, b = 0.0;

    x1 = readValue("x1");
    y1 = readValue("y1");
    x2 = readValue("x2");
    y2 = readValue("y2");

    double *y_intercept = &b;
    double *slope = &m;

    determine_line(&x1,&y1,&x2,&y2,slope,y_intercept);
    printf("\nThe points (%.2lf, %.2lf) and (%.2lf, %.2lf) are on the"
        " line: y = %.2lfx + %.2lf\n",x1,y1,x2,y2,*slope,*y_intercept);
}
void determine_line(double *x1, double *y1, double *x2, double *y2
, double *slope, double *y_intercept)
{
    *slope = (y1-y2)/(x1-x2);
    *y_intercept = y2 - (*slope) * x2 ; // error
}

确定行的所有参数都是指针。您需要取消对指针的引用,以获得可以对其执行算术运算的数字

由于允许指针减法,因此
*slope
赋值不会出现错误,尽管在这种情况下,由于指针不指向相同的对象,结果未定义。但这条线也需要去引用以产生正确的结果

void determine_line(double *x1, double *y1, double *x2, double *y2
, double *slope, double *y_intercept)
{
    *slope = (*y1-*y2)/(*x1-*x2);
    *y_intercept = *y2 - (*slope) * *x2 ;
}

但不清楚为什么前4个参数首先是指针。唯一需要作为指针的参数是
slope
intercept
,因为它们用于返回结果。

谢谢,我尝试过,但我没有在slope中切换它^^^这个问题必须添加坐标,就像它们是函数中的指针一样,尽管对我来说没用。。。