In the example, adapted from a book, I want to fully understand how passing and array by reference really works. From playing with the below code in Code Blocks and some reading here and there, I get that passing by value doesn't change the initial variable's value ( the example_pass_by_value). As for the other two variables whose adresses are passed by reference to the change function, I only understood the example_pass_by_reference case like this : when calling the function like this "change (&example_pass_by_reference), you actually put and "=" sign between the formal parameter "by_reference" ( this being declared as pointer in the change function definition) and the address of "example_pass_by_reference" variable whic is passed to the change function ( ex: by_reference = 0x6644fe, or better by_reference = &example_pass_by_reference); The thing i don't understand is how the "=" is put between the address of array in the calling of function "change(array, ....) and the formal parameter "int arr[]" from definition of the function "change(int arr[], ...)", since int arr[] is an array, not a pointer, to be able to receive the address of variable "array".( like int arr[] = array, or int arr[] = 0x7856ff, for example); Thank you in advance and sorry for the subsequent errors in my code or language.
#include <stdio.h>
#include <string.h>
main()
{
int array[3] = {1,2,3};
int example_pass_by_value = 5;
int example_pass_by_reference = 6;
change(array, example_pass_by_value, &example_pass_by_reference);
printf("Back in main(), the array[1] is now %d.\n", array[1]);
printf("Back in main(), the example_pass_by_value is now %d.\n, unchanged", example_pass_by_value);
printf("Back in main(), the example_pass_by_reference is now %d.\n", example_pass_by_reference);
return(0);
}
/******************************************************************/
change(int arr[], int by_value, int *by_reference)
{
// Changes made to all three variables;
arr[1] = 10;
by_value = 100;
*by_reference = 1000;
return;
}