/* * ===================================================================== * Demonstrate "call-by-value" mechanism in function calls. * * Copyright (C) 1998 by Mark Austin and David Chancogne. * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * * Written By : M. Austin January 1995 * ===================================================================== */ #include int main( void ) { int iVal = 4, iReturnVal; int tryChange( int iVal ); /* function declaration */ /* [a] : Pass value of iVal to tryChange() */ printf("In main() : Passing value of iVal to \"tryChange\"\n" ); iReturnVal = tryChange( iVal ); printf("In main() : Now iVal = %i\n", iVal ); printf(" iReturnVal = %i\n", iReturnVal ); } /* * ======================================================== * tryChange() : Test program for changing parameters. * * Input : int iPassed -- integer passed to tryChange(); * Output : int iPassed -- modified value of iPassed. * ======================================================== */ int tryChange(int iPassed ) { enum{ AddVal = 103 }; /* [a] : Change a parameter that was passed by value */ printf("In tryChange() : iPassed = %i\n", iPassed); printf("In tryChange() : Adding %i to iPassed...\n", AddVal ); iPassed += AddVal; printf("In tryChange() : Now iPassed = %i\n", iPassed); return iPassed; }