#include #include #define INT 0 #define FLOAT 1 void* add(void* a, void* b, char type){ if(type == INT){ int *res = (int*)malloc(sizeof(int)); *res = *(int*)a + *(int*)b; return (void*)res; } else if(type == FLOAT){ float *res = (float*)malloc(sizeof(float)); // We'll do this one differently, more clearly but on more lines float *pa = (float*)a; float *pb = (float*)b; *res = *pa + *pb; return (void*)res; } else { printf("Unsupported type %d!\n", type); } return 0; } void main(){ int a = 5; float b = (float)a; printf("%d\n", a); printf("%f\n", b); float *c = (float*)&a; printf("%f\n", *c); int *d = (int*)&b; printf("%d\n", *d); float e = a / 2.0; printf("%f\n", e); int x = 5, y = 10; int *res = add(&x, &y, INT); printf("result = %d\n", *res); free(res); }