An Example of Aliasing in C++

/* **********************************
The output of this program will be

************************************ */

#include < iostream.h >
//Global Variable
int G_Var;

void AliasingFunction(int& InputVar) //InputVar becomes an alias fo G_Var 
    G_Var = InputVar + 1;       //Uses Global Variable
                                //Same effect as G_Var = G_Var + 1
    cout << InputVar << endl;   
    cout << G_Var << endl;

void main()
    G_Var = 2;
    /*calls SomeFunction with the global Variable as a parameter */

These pages were edited for style and content by Allan Caine, Laura Drever, Gorana Jankovic, Megan King, and Marie Lewis.
The original authors of these pages were Graeme Humphries, Chantal Laplante, Chris Mills, and Melvin Lenz.

Last Modified: Wednesday, June 7th 23:45:30
Copyright 2000 Department of Computer Science, University of Regina.

[CS Dept Home Page]