+ 1

Passing an array to Functions

hello fellow soloLearners, Im very new to coding and c++ in general, and id like to understand a better way to pass an array into a function. When passing an array into a function ,what way is better to pass it with? int func(array[ ], int arraySize); or int func(*array, int arraySize); Is it true that the former will only give you the values, as oppose to the latter gives you the actual address?

23rd Feb 2018, 12:27 AM
Othman Djuliarso
Othman Djuliarso - avatar
3 Answers
23rd Feb 2018, 2:36 AM
Š“ŠµŠ¾Ń€Š³ŠøŠ¹ Š’Š°Š²ŠøŠ»Š¾Š²
Š“ŠµŠ¾Ń€Š³ŠøŠ¹ Š’Š°Š²ŠøŠ»Š¾Š² - avatar
0
hello, thank you for sharing the code up above. When I try to run it in MS Vis Studio 2017, the array[size] produces an error relating to the "size" has to be a const int. Is this a compiler related issue or am I writing the wrong syntax? Thank you in advance..
23rd Feb 2018, 5:45 AM
Othman Djuliarso
Othman Djuliarso - avatar
0
so, instead of inputting the size, i actually have to initialize the size. Then, when it runs, it actually outputs the values of the array elements that I inputted inside the input function; it did not the display the address of elements of the array. So writing void output(int array[], int size) will output the values of that elements, right?
23rd Feb 2018, 5:53 AM
Othman Djuliarso
Othman Djuliarso - avatar