Parameter passing in C++?

31 views Asked by At

So I'm trying to implement heap sort, and I'm having trouble with the parameter passing part. In general, I have this:

int main() {

int array[5];

heapsize = (sizeof(array) / sizeof(*array));

std::cout << "Input 5 integers separated by spaces:" << std::endl;
for (int i = 0; i < 5; ++i)
{
    std::cin >> array[i];
}
cout << "main length of a: " << (sizeof(array) / sizeof(array[0])) << endl;


heapSort(array);

cout << "final output:" << endl;

for (int i = 0; i < 5; ++i)
    cout << array[i] << "  ";

return 0;
}

where I read in an array, and pass that into heapSort(array).

Then I do:

void heapSort(int A[])
{
int n; 
n = (sizeof(A)/sizeof(A[0])); 
cout << "This is n: " << n << endl; //prints out n = 1 
build_max_heap(A); 
}

I mean to pass the array[5] into heapsort(int A[]), so why is the length showing up as 1?

0

There are 0 answers