#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;

void swap (int *ap, int *bp) {
    int temp = *ap;
    *ap = *bp;
    *bp = temp;
}

void swap1 (void *ap, void *bp, int size) {
	char temp[size];
    memcpy (temp, ap, size);
    memcpy (ap, bp, size);
    memcpy (bp, temp, size);
}

int main ()
{
    int i = 15;
    int j = 61;
	cout << "Before swap" << endl;
    cout << "i = " << i << endl;
    cout << "j = " << j << endl;
    swap1 (&i, &j, sizeof (int));
	cout << "After swap" << endl;
    cout << "i = " << i << endl;
    cout << "j = " << j << endl;

    double x = 3.14156;
    double y = 61.2534;
	cout << "Before swap" << endl;
    cout << "x = " << x << endl;
    cout << "y = " << y << endl;
    swap1 (&x, &y, sizeof (double));
	cout << "After swap" << endl;
    cout << "x = " << x << endl;
    cout << "y = " << y << endl;

    int p = 132769;
	short q = 5;
	cout << "Before swap" << endl;
    cout << "p = " << p << endl;
    cout << "q = " << q << endl;
    swap1 (&p, &q, sizeof (short));
	cout << "After swap" << endl;
    cout << "p = " << p << endl;
    cout << "q = " << q << endl;
}
