title: Array of function pointers in C with different return types and arguments
body: <p>I have 3 functions with different return types and different arguments. I am trying to create an array of function pointers and then call them afterwards. But its not working. Please provide some suggestions.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  /* Array of function pointers (different return types and parameters) */
  
  void sayHello()
  {
      printf("Hello World\n");
  }
  
  int add(int a, int b)
  {
      return a+b;
  }
  
  int twice(int a)
  {
      return 2*a;
  }
  
  int main()
  {
      int choice;
      int(*add_ptr)(int,int) = NULL;
      void(*hello_ptr)(void) = NULL;
      int(*twice_ptr)(int) = NULL;
  
      void * func_table[] = {(void *)sayHello, (void *)add, (void *)twice};
  
  
      printf("Add : %d\n", ((add_ptr)func_table[1])(10,5));
      printf("Hello : \n",((hello_ptr)func_table[0])());
      printf("Twice : %d\n",((twice_ptr)func_table[2])(10));
      return 0;
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have edited the code to look like : </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  /* Array of function pointers (different return types and parameters) */
  
  void sayHello()
  {
      printf("Hello World\n");
  }
  
  int add(int a, int b)
  {
      return a+b;
  }
  
  int twice(int a)
  {
      return 2*a;
  }
  
  int main()
  {
      int choice;
      typedef int(*add_ptr)(int,int);
      typedef void(*hello_ptr)(void);
      typedef int(*twice_ptr)(int);
  
      void * func_table[] = {(void *)sayHello, (void *)add, (void *)twice};
  
  
      printf("Add : %d\n", ((add_ptr)func_table[1])(10,5));
      printf("Hello : ",((hello_ptr)func_table[0])());
      printf("Twice : %d\n",((twice_ptr)func_table[2])(10));
      return 0;
  }
  </code></pre>
  
  <p>But still I am getting the error : </p>
  
  <pre><code>error: invalid use of void expression
    printf("Hello : ",((hello_ptr)func_table[0])());
    ^
  </code></pre>