title: Difference between Functions and Function Pointers as Arguments
body: <p>This is a rather simple question that is making me a bit curious. Consider the following code snippet:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int three()
  {
      return 3;
  }
  
  void foo(int func(void))
  {
      std::cout &lt;&lt; func() &lt;&lt; std::endl;
  }
  
  void bar(int (*func)(void))
  {
      std::cout &lt;&lt; func() &lt;&lt; std::endl;
  }
  
  int main()
  {
      foo(three);
      bar(three);
      return 0;
  }
  
  // output:
  // 3
  // 3
  </code></pre>
  
  <p>As you can see, we have two functions that take another function as their only argument. However, the function prototypes for them differ. Mainly, we have <code>void foo(int func(void))</code> and <code>void bar(int (*func)(void))</code>. At first glance, it looks like <code>foo</code> is taking the function itself, and <code>bar</code> is taking a pointer to a function.</p>
  
  <p>However, they both produce the exact same results, and have the exact same body, and are called in exactly the same manner.</p>
  
  <p>My question is, is there an actually hidden difference between <code>foo</code> and <code>bar</code>? Is this simply an optional syntax in C++? Is one of the two cases considered "bad style" in C++?</p>
  
  <p>If my compiler is a contributing factor, I'm using Visual Studio 2010.</p>