OK -
I am working on a snippet of code to make a recursive function that sorts values. I have kept banging on the code trying to make it work as I want it too. The code now runs and works as expected - but it is bothering me that I don't really know why my code is working... I think I know why it is working but I wanted to check with someone who can confirm my thinking....
I made a couple of functions - one was a recursive function to sort and the second function was to print out an array. In each function call I pass the entire array and an integer value. When I first tried to pass the array I would put brackets in and array count in.. and clang would puke. I kept trying different syntax combinations until I could pass the array by just giving the function the name of the array and the name of the array count variable.
My question is as follows - when I pass the entire array am I only passing a pointer to the location where the array is? How does C know I am passing the array by reference and not passing by value?
After looking at my code - I can only conclude that I am passing by reference because the operations I do on the array "take hold" in every iteration of the recursion process... but
When I am passing the array to the function my code looks like the following...
int array_size = 6;
int array_list[] = {23, 42, 4, 16, 8, 15};
//Print out Array
print_Array(array_list,array_size);
//Call recursive function to sort arrays:
fn_sort_integers(array_list,array_size);
//Print out Array
print_Array(array_list,array_size);
void fn_sort_integers(int input[], int n)
{
//Sorting done here
//Recursive call to fn_sort_integers
}
void print_Array(int input[], int n)
{
//Print Array
}