I've got message warning C4090: '=': different 'const' qualifiers
when compiling my C program.
I've seen some info here, here and even here. But I still don't understand how are they related with my problem. For compiling I use Visual C++ 2015 x64 Native Build Tools Command Prompt.
I know that it's because of using const
in function declaration. But array is not changing. So what's the deal?
Here is my code:
#include <stdio.h>
int sum_array(const int a[], int n)
{
int *p, sum;
sum = 0;
for (p = a; p < a + n; p++)
sum += *p;
return sum;
}
int main(void)
{
int a[5] = {1, 2, 3, 4, 5};
printf("%d", sum_array(a, 5));
return 0;
}
Program works well, I just want to understand why I get this warning.