Allocating arrays of function pointers in C
Dynamically allocate array of 2 pointers to functions returning int and taking no argument.
1 2 3 4 5 6 7 8 9 |
int test1() {printf "test1"; return 0;} int test2() {printf "test2"; return 0;} int main(int argc, char* argv[]) { int (*(*f_arr))() = malloc(sizeof(int (*)()) * 2); f_arr[0] = &test1; f_arr[1] = &test1; } |
Statically allocate array of 2 pointers to functions returning int and taking no argument.
1 2 3 4 5 6 7 8 |
int test1() {printf "test1"; return 0;} int test2() {printf "test2"; return 0;} int main(int argc, char* argv[]) { int (*f_arr[2])() = {test1, test2}; return testRunner(f_arr, 2); } |