I am trying to get a better understanding of pointers.
Could someone please explain why all the alternatives work?
And are there any more alternatives?
Code:
#include <stdio.h>
//float summate(float*);// A
//float summate(float[]);// B
float summate(float z[]);
int main()
{
float result;
float a[] = {23.4, 55, 22.6, 3, 40.5, 18};
result = summate(&a[0]); // could just be summate(a);
printf("Result = %.2f", result);
return 0;
}
//float summate(float* x) // C
float summate(float x[])
{
float sum = 0.0;
for (int i = 0; i < 6; ++i)
{
sum += x[i];
}
return sum;
}