Array Size of and definition, wrong outcome always 46 for the first array element
#include <iostream> using namespace std; int aver(int data[]=0) { float add=0; int n; for(int i = 0, length = sizeof(data); i < length+2; ++i) { cout<<" "<<"Array No. "<<i+1<<" "<<data[i]<<endl; int x=sizeof(data); add=add+data[i]; cout<<endl; n=i+1; } cout<<"The addition is = "<<add<<endl; float ave=add/n; cout<<"The Average of the six numbers is = "<<ave<<endl; } OUTPUT Below. Why the first element of the Array is always 46? This Program Adds the elements of an Array And calculates their Average how many elements do you want in the Array? 6 enter 1 Element 2 enter 2 Element 3 enter 3 Element 4 enter 4 Element 5 enter 5 Element 6 enter 6 Element 7 Array No. 1 46 Array No. 2 2 Array No. 3 3 Array No. 4 4 Array No. 5 5 Array No. 6 6 The addition is = 66 The Average of the six numbers is = 11 Process returned 0 (0x0) execution time : 7.212 s Press any key to continue