C 对数组使用函数?代码不';行不通

C 对数组使用函数?代码不';行不通,c,arrays,function,C,Arrays,Function,为什么这个代码不起作用?我知道还有其他方法,但一定是这样。我如何解决这个问题 #include <stdio.h> #include <stdlib.h> int total(int arr[3], int size_of_array){ int i=0; int total=0; for(i=0;i<size_of_array;i++){ total+=arr[i]; } return total

为什么这个代码不起作用?我知道还有其他方法,但一定是这样。我如何解决这个问题

#include <stdio.h>
#include <stdlib.h>

int total(int arr[3], int size_of_array){

    int i=0;
    int total=0;

    for(i=0;i<size_of_array;i++){

        total+=arr[i];

    }

    return total;

}


int main(){


    int array2[3]= {0,1,8};

    int total(array2, 3);


}
#包括
#包括
整数总计(整数数组[3],整数数组的整数大小){
int i=0;
int-total=0;

对于(i=0;i有什么问题?你不能说
int-total(array2,3);
。你是说
printf(“%d\n”,total(array2,3));
?@squemishossifrage Im noob在C编程中,但在函数中,它已经返回了。我认为“返回”的“total”与printf是一样的。那么“返回”方法有什么意义呢?
int main(){
    int array2[3]= {0,1,8};
    int theAnswer;                           // Make an integer for the result.
    theAnswer = total(array2, 3);            // Call the function, and store the result.
    printf("The answer is %d\n", theAnswer); // Show the result to the user

    return 0;                                // main has to return 0 to indicate "success"
}