ex2-1.cpp - Example 2-1 Reference Variables - swap function

// File:  ex2-1.cpp Reference Variables - swap functions

#include <iostream>
using namespace std;

// Function prototypes (required in C++)
void pointerSwap(int*, int*);
void referenceSwap(int&, int&);

int main (void)
{
	int x = 5;
	int y = 7;

	cout << x << ' ' << y << endl;

	pointerSwap(&x,&y);

	cout << x << ' ' << y << endl;

	referenceSwap(x,y);

	cout << x << ' ' << y << endl;

	return 0;
}

void pointerSwap(int *a, int *b)
{
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

void referenceSwap(int &a, int &b)
{
	int temp;
	temp = a;
	a = b;
	b = temp;
}



CIS27: Programming in C++    Instructor: Joe Bentley