I am using gcc compiler in ubuntu18.10 os. And I don't know why this program is giving Error and Can't even understand the error. The Program is as follows and I presented ERRORS also.
#include<stdio.h>
#include<stdlib.h>
float Average(int*, int);
int main()
{
int *arr;
int n;
scanf("%d",&n);
float sum;
arr = (int *)malloc(n * sizeof(int));
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
sum = Average(int *arr, int n);
printf("%f\n",sum);
return 0;
}
float Average(int *arr, int size)
{
int sum;
int n = size;
printf("arr: %p\n",&arr);
printf("size: %p\n",&size);
printf("sum: %p\n",&sum);
for(int i=0;i<n;i++)
{
sum += arr[i];
}
return (sum * 1.0f) / size;
}
Errors are:
Test.c: In function ‘main’:
Test.c:16:16: error: expected expression before ‘int’
sum = Average(int *arr, int n);
^~~
Test.c:16:8: error: too few arguments to function ‘Average’
sum = Average(int *arr, int n);
^~~~~~~
Test.c:4:7: note: declared here
float Average(int*, int);
^~~~~~~
Please Help me to find out why and any reference materials to understand the concept clearly. Thank you
gcc, at a minimum use:-Wall -Wextra -Wconversion -pedantic -std=gnu11) Note other compilers use different options to output the same things. Note: the posted code causes the compiler to output 6 warning and 2 error messages.