Pointers and array paramters

Hi, I have a question related to this topic because I am doing a homework assignment and want to make sure that my understanding is sound.
I have a function called Menu that has two parameters; an array of structs and int variable for the size of the array. I just need clarification on the argument aspect. Specifically, I have created a dynamically allocated array and have passed the pointer as an argument into the Menu function and it works. My question is, how is this working? Is it because an array is essentially a pointer to the first address of the array and because of this the pointer argument passed in an equivalent argument? or is there something else going on here I'm not understanding? Thank you in advance for the assistance.

//dynamically allocated array
TD* PTR = new TD[size];


//function call
Menu(PTR, size);


//function definition
void Menu(TD arr[], int &amount)
{
.....
}


My question is, how is this working?

Realize that the following are basically the same:

1
2
void Menu(TD arr[], int &amount);
void Menu(TD *arr, int &amount);


Is it because an array is essentially a pointer to the first address of the array and because of this the pointer argument passed in an equivalent argument?

So the answer to this question, is basically yes. When you pass an array to a function you are actually passing the address of the array. The name of the array will decay to the array address.
Topic archived. No new replies allowed.