CS 211 - 8/26/16 pass-by-value = copies are send to the function, modifying the copy does not change the original pass-by-reference = a reference to the original is sent to the function modifying the reference does update the original the "pass-by-reference" syntax in C is often called "pass-by-address" /* void f1 ( int *a , int sz ) */ void f1 ( int a[] , int sz , int *xp) { sz = 10; *xp = 20; } int main() { int arr[50]; /* allocates space for 50 integers on the stack */ int *arr2; /* allocates space for one address on the stack */ /* most often used for a dynamic array */ int x = 0; /* allocates 50 integers for the dynamic array */ int size2 = 50; arr2 = (int*) malloc ( size2 * sizeof(int) ); int i = 0; while ( MORE INPUT ) { scanf ( "%d", &val); /* check if the array is full before adding the value */ if ( i >= size2 ) { /* add more space in the array - this code doubles the array size */ int *temp; temp = (int *) malloc ( size2 * 2 * sizeof(int) ); /* copy existing value to new memory space */ int i; for ( i = 0 ; i < size2 ; i++) temp[i] = arr2[i]; /* de-allocate the old memory space */ free (arr2); /* update the variables to reflect the larger memory space */ arr2 = temp; size2 = size2 * 2; } arr2[i] = val; i++; } .. f1 ( arr, size, &x ); }