title: Trying to understand function pointers in C
body: <p>I am trying to understand function pointers and am stuggling. I have seen the sorting example in K&amp;R and a few other similar examples. My main problem is with what the computer is actually doing. I created a very simple program to try to see the basics. Please see the following:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int func0(int*,int*);
  int func1(int*,int*);
  
  int main(){
  
      int i = 1;
      myfunc(34,23,(int(*)(void*,void*))(i==1?func0:func1));//34 and 23 are arbitrary inputs
  
  
  
  }
  
  void myfunc(int x, int y, int(*somefunc)(void *, void *)){
  
      int *xx =&amp;x;
      int *yy=&amp;y;
  
      printf("%i",somefunc(xx,yy));
  
  
  }
  
  int func0(int *x, int *y){
  
      return (*x)*(*y);
  
  }
  
  int func1(int *x, int *y){
  
      return *x+*y;
  } 
  </code></pre>
  
  <p>The program either multiplies or adds two numbers depending on some variable (i in the main function - should probably be an argument in the main). fun0 multiplies two ints and func1 adds them.</p>
  
  <p>I know that this example is simple but how is passing a function pointer preferrable to putting a conditional inside the function myfunc? 
  i.e. in myfunc have the following:</p>
  
  <pre><code>if(i == 1)printf("%i",func0(xx,yy));
  
  else printf("%i",func1(xx,yy));
  </code></pre>
  
  <p>If I did this the result would be the same but without the use of function pointers.</p>