The following is the code that I am currently struggling with:
I want to have a function pointer whose return type can be of any data type and whose arguments can be of any data type (there can be multiple arguments).
Code:
#include<stdio.h>
int* numbers(int *);
char* alphabets(char[]);
void* functions(void* (*myfunction)(void *));
int main(int argc, char *argv[])
{
typedef void* (*myfunction)(void*);
myfunction fun = &numbers;
char *array, letters[20] = {'v','i','v','e','n','\0'};
int a = 2;
int *y;
y = fun(&a);
printf("%d\n",*y);
fun = &alphabets;
array = fun(letters);
printf("%s\n",array);
}
int* numbers(int *k)
{
return k;
}
char* alphabets(char *ptr)
{
return ptr;
}
void* functions(void* (*myfunction)(void *))
{
return myfunction;
}
The above code is my attempt to achieve generic function pointer.
Thank you.