/* ////////////////////////////////////////////////////////////////// // Sample #1: by value // Sending variables by value. ////////////////////////////////////////////////////////////////// */ #include int max_plus( int, int ); int main (){ int x = 31; int y = 513; z = max_plus( x, y ); printf("The max of %d and %d is %d\n", x, y, z ); return 0; } int max_plus( int a, int b ){ int temp; printf("In MAX:\n"); printf("FORMAL Parameters: At the Start\n"); printf("The first parameter = a."); printf(" The value of a = %d\n", a ); printf("The second parameter= b" ); printf(" The value of b = %d\n\n", b ); if( a > b ) temp = a; else temp = b; a += 10; b += 20; printf("In MAX:\n"); printf("FORMAL Parameters: At the Start\n"); printf("The first parameter = a."); printf(" The value of a = %d\n", a ); printf("The second parameter= b" ); printf(" The value of b = %d\n\n", b ); printf("Did a and b change?\n"); return( temp ); } -----------------------cut here---------------------------- /* ////////////////////////////////////////////////////////////////// // Sample #2: parameters // Sending variables by reference. // // The only difference between #1 and #2: // #1 is by value // #2 is by reference ////////////////////////////////////////////////////////////////// */ #include int max_plus( int*, int* ); int main (){ int x = 31; int y = 513; int z; printf("In Main:\n"); printf("Actual Parameters: BEFORE the call\n"); printf("The first parameter = Y."); printf(" The value of y = %d\n", y ); printf("The second parameter= X" ); printf(" The value of x = %d\n\n", x ); z = max_plus( &x, &y ); printf("In Main:\n"); printf("Actual Parameters: AFTER the call\n"); printf("The first parameter = Y."); printf(" The value of y = %d\n", y ); printf("The second parameter= X" ); printf(" The value of x = %d\n\n", x ); printf("Did x and y change?\n"); printf("The max of %d and %d is %d\n", x, y, z ); return 0; } int max_plus( int *a, int *b ){ int temp; printf("In MAX:\n"); printf("FORMAL Parameters: At the Start\n"); printf("The first parameter = a."); printf(" The value of a = %d\n", *a ); printf("The second parameter= b" ); printf(" The value of b = %d\n\n", *b ); if( *a > *b ) temp = *a; else temp = *b; *a += 10; *b += 20; printf("In MAX:\n"); printf("FORMAL Parameters: At the Start\n"); printf("The first parameter = a."); printf(" The value of a = %d\n", *a ); printf("The second parameter= b" ); printf(" The value of b = %d\n\n", *b ); printf("Did a and b change?\n"); return( temp ); }