saiz66 Posted June 28, 2004 Share Posted June 28, 2004 (edited) How would I pass a dynamic array into a function by reference? By the way this is my array: int *element = new int[N] Thanks! Edited June 28, 2004 by saiz66 Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted June 28, 2004 Share Posted June 28, 2004 Arrays are passed by reference by default as the array variable is actually a pointer to the first element of the array. Your prototype for your function would be smiliar to... void MyFunc( int* array, const int lengthOfArray ); If you don't want side effects( changes in your array ), you'd need to specify the array as const in the parameters of the function. Nothing changes in the way the function is called. It would be a compile error if you tried to modify the array in MyFunc. void MyFunc( const int* array, const int lengthOfArray ); Link to comment Share on other sites More sharing options...
0 saiz66 Posted June 28, 2004 Author Share Posted June 28, 2004 thank you! Link to comment Share on other sites More sharing options...
Question
saiz66
How would I pass a dynamic array into a function by reference? By the way this is my array:
Thanks!
Edited by saiz66Link to comment
Share on other sites
2 answers to this question
Recommended Posts