Here is my code. I am not sure why the number of elements in my array is 2. Can anyone explain this?
#include <stdio.h>
int calculate(int age[]);
int main()
{
int result, age1[]= {23,17,18,22,27,35};
result=calculate(age1);
printf("%d\n", result);
return 0;
}
int calculate(int age[])
{
int sum=0;
int size;
size=sizeof(age)/sizeof(age[0]);
printf("Size:%d\n", size);
for(int i=0; i<size;i++)
{
sum+=age[i];
}
return sum;
}
I couldn't get the sum of all elements. It only adds the first 2 elements in the array.