fork download
  1. #include <stdio.h>
  2.  
  3. typedef int (*FUNC_PTR_T)(void);
  4. typedef struct foo_type { FUNC_PTR_T array[3]; } FOO_T;
  5.  
  6. int foo1(void) { return 1; }
  7. int foo2(void) { return 2; }
  8. int foo3(void) { return 3; }
  9.  
  10. FOO_T getFuncs(void)
  11. {
  12. FOO_T r;
  13. r.array[0] = foo1;
  14. r.array[1] = foo2;
  15. r.array[2] = foo3;
  16. return r;
  17. }
  18.  
  19. int main(void)
  20. {
  21. FOO_T r = getFuncs();
  22. int i;
  23. for (i=0; i<3; i++) {
  24. printf("r.array[%d] = %d\n", i, r.array[i]());
  25. // printf("r.array[%d] = %d\n", i, (*r.array[i])());
  26. }
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 5476KB
stdin
Standard input is empty
stdout
r.array[0] = 1
r.array[1] = 2
r.array[2] = 3