gpt4 book ai didi

c++ - C、编译错误和指针

转载 作者:太空宇宙 更新时间:2023-11-04 02:54:27 24 4
gpt4 key购买 nike

我在传递 float 数组时遇到了一些问题。我将一些 float 数组放入 ActivationFunc,然后从那里将这些相同的数组放入 sgnFunction,由于某种原因最终具有不同的值。

#include <stdio.h>
void sgnFunction(float *input[], float *weight[])
{
printf("VALUES: %.2f %.2f %2.f, WEIGHTS: %.2f, %.2f, %.2f\n", *input[0], *input[1], *input[2], *weight[0], *weight[1], *weight[2]);
}

void ActivationFunc(float *x, float *w, float *n, int *d)
{
printf("VALUES: %.2f %.2f %2.f, WEIGHTS: %.2f, %.2f, %.2f\n", x[0], x[1], x[2], w[0], w[1], w[2]);
sgnFunction(&x, &w);
}

int main()
{
float x1[3] = {1, 0, 1};
float x2[3] = {0, -1, -1};
float x3[3] = {-1, -0.5, -1};
int d[3] = {0, 1, 1};
float w[3] = {1, -1, 0};
float n = 0.1;

ActivationFunc(x1, w, &n, &d[0]);
}

如果我从“sgnFunction(&x, &w);”中删除“&”,我会得到一个编译器错误:

test.c: In function 'ActivationFunc':
test.c:10:9: warning: passing argument 1 of 'sgnFunction' from incompatible pointer type
test.c:2:14: note: expected 'float **' but argument is of type 'float *'

我不明白修复它意味着什么。我知道我可能只是在使用指针时搞砸了。非常感谢对错误的解释、我的指针做错了什么以及如何解决这个问题。

最佳答案

如果你这样调用函数

 sgnFunction(x, w);  

你的定义应该是

void sgnFunction(float *input, float *weight) // you just need to change array of pointers to single pointer 
{
printf("VALUES: %.2f %.2f %2.f, WEIGHTS: %.2f, %.2f, %.2f\n", input[0], input[1], input[2], weight[0], weight[1], weight[2]); // here also
}

关于c++ - C、编译错误和指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19150483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com