please can someone tell me why these code, when run prints 1 instead of 3.5 to the console. it implemnts passing an array to a function, to calculate average of the array elements. i used the sizeof(array)/sizeof(int) as array length
#include "stdafx.h"
#include <iostream>
// function avg, to calculate average of an integer array.
double avg(int iArray[])
{
// initialize variable y to calculate sum
// initialize variable to calculate length of array
int y{}, z = sizeof(iArray) / sizeof(int);
// loop over array elements
for (int i{}; i < z; i++)
{
y += iArray[i];
}
// return average to caller
return ((double)y) / z;
}
int main()
{
using namespace std;
// initialize array.
int iArray[] = { 1, 2, 3, 4, 5, 6 };
// call avg function, and assign return value to variable z.
double z = avg(iArray);
// print average to console
cout << z << endl;
return 0;
}