Code:
#include <stdio.h>
#define size 5
int GetSum(int *,int);//can't just prototype as array will only be array[0] need MAX_SIZE
int main(void){
const int list[size]={23,34,45,56,90};
int ndx, sum = 0;
int total = 0;
int value;
for(ndx =0; ndx<size; ndx++){
printf("%d = %d\n", ndx, list[ndx]);
}
value = GetSum(list, size);
printf("Value of List using the function is %d\n", value);
//sum up elements of array list
for(ndx = 0; ndx < 5; ndx++){
printf("Sum will be %d + %d\n", sum, list[ndx]);
sum = sum + list[ndx];//value at list ndx
//sum +=list[ndx]; sum
printf("Sum is now %d\n", sum);
}
getchar();
return 0;
}
GetSum(int list[], int n){
int ndx, sum=0;
for (ndx = 0; ndx < n; ndx++)
sum +=list[ndx];
return sum;
}
i'm getting a warning when this compiles saying
passing arg 1 of `GetSum' discards qualifiers from pointer target type
Any ideas why?