I'm trying to protect the -a- array of the my_sum_array function from the changes. In the function block I do not make any changes to -a-, but I have a warning (warning: assignment to 'int *' from 'const int *' discards the qualifiers [-Wincompatible-pointer-types-discards-qualifiers]). I know I could remove const to make the program work, but I would like to understand if something is missing from me.
#include <stdio.h>
#define MAX 5
int my_sum_array(const int a[], int n);
int main(void) {
int values[5] = {4, 7, 1, 7, 8};
printf("The sum in my_sum_array is :%d\n", my_sum_array(values, MAX));
return 0;
}
int my_sum_array(const int a[], int n) {
int *p, sum = 0;
for (p = a; p < a + n; p++)
sum += *p;
return sum;
}