An Example of Aliasing in C


/********************************
An example of aliasing in C.

Output:
3
3

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

#include < stdio.h >

int main()

{

   int G_Var = 2;

   /* call SomeFunction with the Global Variable as a parameter */

   SomeFunction(G_Var); 

   return 0;
}

/* InputVar becomes an alias fo G_Var */

void SomeFunction(int &InputVar)
{

   int G_Var;
   int InputVar;

   /* Global Variable is set to new value */

   G_Var = InputVar + 1;       

   /* Equivalent to G_Var = G_Var + 1 */

   printf("%i\n", InputVar);

   printf("%i\n", G_Var);

}

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]