I have an array of function pointer:
int (*collection[2]) (int input1, int input 2) = {&fct1,&fct2}
I can get values by calling both functions from the array:
*collection[0](1,2);
*collection[1](1,2);
Using typedef, I want another way to invoke the array of function pointer. So far, I am doing:
typedef int (*alternameName)(int input1, int input 2);
alternateName p = &collection[2];
int result1 = (*p[0])(1,2);
int result2 = (*p[1])(1,2);
printf("results are: %d, %d",result1, result2);
My issue is I do not think I properly defined the variable p as I keep getting 0 as my results.
alternateName p = &collection[2];Assuming that this is the samecollectionas above, you take the address of the third element, which does not exist. TryalternateName p = collection;oralternateName p = &collection[0];