【发布时间】:2021-07-04 18:30:56
【问题描述】:
有人可以帮我修复这段代码中的语法错误吗?
#include <stdio.h>
int result(int v, int size);
int main(void){
int arr[5], n;
for (n = -1; n < 4; n++){
arr[n] = n + 1;
printf("the product of entered values is %d", result(n, 5));
}
return 0;
}
int product(int a[]) {
int product, i;
for (i = 0; i <= sizeof(int); i++){
product *= a[i];
}
return product;
}
【问题讨论】:
-
如果您遇到错误,请在帖子中显示。您是否搜索过这些错误?通常,只需将整个错误粘贴到搜索引擎中,就会显示有关如何修复它的相关信息的帖子。最后,请使用一致的空格和缩进格式化您的代码以使其可读。
-
编译因以下错误而失败。/tmp/ccKrYzlA.o: In function
main': /home/main.c:20: undefined reference toresult' collect2: error: ld returned 1 exit status -
数组从 0 开始,而不是 -1。
-
那么
result在哪里? -
错误不是自我解释的吗?您正在调用
result,但没有提供该函数的任何定义。它是否在您未显示的其他地方定义?
标签: arrays c for-loop indexing function-definition