/* Filename: params.cpp Author: Br. David Carlson Date: January 13, 1998 Revised: July 20, 2000; November 21, 2001 This program illustrates some features of parameter passing. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET g++ under Linux */ #include using namespace std; // Global variable (usually best to avoid these): int num; // Function prototypes: int calc(int & x, int y); void compute(int b); int main(void) { int a, b, ans; ans = 1; num = 2; a = 3; b = 4; ans = calc(a, b); cout << "main -- values of a, b, ans, num: " << a << " " << b << " " << ans << " " << num << endl; compute(b); cout << "main -- values of a, b, ans, num: " << a << " " << b << " " << ans << " " << num << endl; return 0; } int calc(int & x, int y) { int c; x++; // shorthand for x = x + 1 y--; // shorthand for y = y - 1 c = x + 2 * y; cout << "calc -- values of x, y, c, num: " << x << " " << y << " " << c << " " << num << endl; return c; } void compute(int b) { b = b + 10; num = 37; cout << "compute -- values of b, num: " << b << " " << num << endl; }