• 0

[C++] Passing Arrays as reference


Question

4 answers to this question

Recommended Posts

  • 0

int sum_arr(int arr[], int) //using index notation

is the same as

int sum_arr(int * arr, int) //passing by address

Not sure if this helps.

When passing an array by an address you are really passing by a pointer. When this is the case the pointer pointers to the first index within the array.

Edited by Genesi
Link to comment
Share on other sites

  • 0

thank u genesi again!

int sum_arr(int * arr, int) //passing by address

in my main program would I pass it like this?

int arr[50];

sum_arr(arr, int) ?

I have a way of forgetting things... any resource available online where they have examples to refresh my memory?

Edited by saiz66
Link to comment
Share on other sites

  • 0
thank u genesi again!

int sum_arr(int * arr, int) //passing by address

in my main program would I pass it like this?

int arr[50];

sum_arr(arr, int) ?

I have a way of forgetting things... any resource available online where they have examples to refresh my memory?

Yes, although I'm sure he forgot size for the name of the second parameter, since in C you can't really tell the size of an array when it gets passed.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.