C++语言程序设计

| 例5-10

#include <iostream.h>
void Foo (int first, int second, int third)
{
cout << "Original function values "
<< "first = " << first
<< "second = " << second
<< "third = " << third
<<endl;
first += 50;
second += 50;
third += 50;
cout << "Ending function values "
<< "first = " << first
<< "second = " << second
<< "third = " << third
<<endl;
}
void main (void)
{
int x = 1, y = 2, z = 3;
Foo(x,y,z);
cout << "Ending values in main "
<< "first = " << x
<< "second = " << y
<< "third = " << z
<<endl;
}

编译并执行，屏幕将显示如下结果：
Original function values first = 1 second = 2 third = 3
Ending function values first = 51 second = 52 third = 53
Ending values in main first = 1 second = 2 third = 3
可以看到，函数对变量所作的改变只在函数内部有效。