fork download
  1. #include <stdio.h>
  2.  
  3. typedef int (*fx)(void); // fx is pointer to function taking no parameters and returning int
  4.  
  5. int foo_1(void) { printf("%s\n", __func__); return 1; }
  6. int foo_2(void) { printf("%s\n", __func__); return 2; }
  7. int foo_three(void) { printf("%s\n", __func__); return 3; }
  8.  
  9. int main(void) {
  10. fx foo[3] = { foo_1, foo_2, foo_three };
  11. for (int k = 0; k < 3; k++) {
  12. printf("foo[%d]() returns %d\n", k, foo[k]());
  13. }
  14. }
  15.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
foo_1
foo[0]() returns 1
foo_2
foo[1]() returns 2
foo_three
foo[2]() returns 3