/* ////////////////////////////////////////////////////////////////// // Sample #1: parameters // A sample Program to see how parameters work! ////////////////////////////////////////////////////////////////// */ #include int max( int, int ); int main (){ int x = 31; int y = 513; int z; printf("In Main:\n"); printf("These are the ACTUAL Parameters\n"); printf("The first parameter = x."); printf(" The value of x = %d\n", x ); printf("The second parameter= y" ); printf(" The value of y = %d\n\n", y ); z = max( x, y ); printf("Did a == x?\n"); printf("Did b == y?\n\n"); printf("The max of %d and %d is %d\n", x, y, z ); return 0; } int max( int a, int b ){ printf("In MAX:\n"); printf("These are the FORMAL Parameters\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 ) return a; else return b; } -----------------------cut here---------------------------- /* ////////////////////////////////////////////////////////////////// // Sample #2: parameters // A sample Program to see how parameters work! // // This version is left for your own observations. The only // difference between this one and #1, I've reversed the order // of x and y in the call to max. What happens when I do this? ////////////////////////////////////////////////////////////////// */ #include int max( int, int ); int main (){ int x = 31; int y = 513; int z; printf("In Main:\n"); printf("These are the ACTUAL Parameters\n"); /******************************************************** * In the first program X was first, and Y was Second. * * What happens if we do it this way? * * Will a still equal x? Will b still equal b? * * If you don't know, run this program and find out. * * Make as many sample programs as it takes to convince * * yourself about how parameters and functions work. * ********************************************************/ 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( x, y ); printf("Did a == x?\n"); printf("Did b == y?\n\n"); printf("The max of %d and %d is %d\n", x, y, z ); return 0; } int max( int a, int b ){ printf("In MAX:\n"); printf("These are the FORMAL Parameters\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 ) return a; else return b; }