I tried to write a generic swap() for char,short,int,long,float,double all the standard data types. But it is not working the way I thought it will :(Code:#include <stdio.h>
void swap(void *a, void *b) {
void *t;
t = a;
a = b;
b = t;
}
int main() {
int i, j;
double f, g;
i = 1;
j = 2;
f = 1.1;
g = 2.2;
printf("Before: %d, %d & %f, %f\n", i,j, f,g);
swap(&i, &j);
swap(&f, &g);
printf("After: %d, %d & %f, %f\n", i,j, f,g);
return 0;
}