Complete listing of Functions04.cpp
/*File: Functions04.cpp
This C++ program illustrates functions with value
parameters, reference parameters, and no return
value
This program displays the following text on the
screen:
In main
a = 10 b = 20.1
In aFunction
x = 10 y = 20.1
Change x and y
Still in aFunction
x = 100 y = 200.1
Back in main
a = 100 b = 20.1
************************************************/
#include <iostream>
using namespace std;
//Note that the first parameter is a reference
// parameter.
void aFunction(int &x,double y){
cout << "In aFunction" << endl;
cout << "x = " << x << " y = " << y << endl;
cout << "Change x and y" << endl;
x = 100;
y = 200.1;
cout << "Still in aFunction" << endl;
cout << "x = " << x << " y = " << y << endl;
}//end aFunction
//---------------------------------------------//
int main(){//Global main function.
cout << "In main" << endl;
int a = 10;
double b = 20.1;
cout << "a = " << a << " b = " << b << endl;
aFunction(a,b);
cout << "Back in main" << endl;
cout << "a = " << a << " b = " << b << endl;
return 0;
}//end main function
Listing 4
|