I have just begun using C++, with a base in C. Having learned about Call by reference, I need to know,if in the following function I found online:
int insertSorted(int arr[], int n, int key, int capacity)
{
if (n >= capacity)
return n;
arr[n] = key;
return (n+1);
}
,which is used for insertion in an unsorted array, will the array in the main function get affected/changed? Since the arr[]
argument in the function is not a reference variable, so how do any changes in this called function, reflect in the calling function? Is this correct code, if at all? I am basing my question upon the fact that call by value, creates copy variables and changes them, while call by reference changes the actual variables themselves. I'm sorry if this question is a bit silly.
Any help in clearing up this concept would be great.
Thanks.