I am trying to create an array of function pointers, so that I can print out output from the functions by using the pointers. (For an exercise from the Effective C book.)
#include <stdio.h>
#include <stdlib.h>
int a(void) { return 1; }
int b(void) { return 2; }
int c(void) { return 3; }
int main(void)
{
int(*func_arr)[3] = {&a, &b, &c};
printf("%d\n", (*func_arr)[0]);
}
However, when I compile it, I get the warnings
starting.c:10:26: warning: incompatible pointer types initializing 'int (*)[3]' with an expression of type
'int (*)(void)' [-Wincompatible-pointer-types]
int(*func_arr)[3] = {&a, &b, &c};
^~
starting.c:10:30: warning: excess elements in scalar initializer
int(*func_arr)[3] = {&a, &b, &c};
^~
And, when I run the program, I get an output of -443987883, while it should just be 1.
Does anyone know the solution for this? Thank you!