title: What is the address of a function in a C++ program?
body: <p>As the function is set of instruction stored in one contiguous block of memory.</p>
  
  <p>And address of a function (entry point) is the address of the first instruction in the function. (from my knowledge)</p>
  
  <p>And thus we can say that the address of function and the address of the first instruction in the function will be the same (In this case the first instruction is the initialization of a variable.).</p>
  
  <p>But the program below contradicts the above line.</p>
  
  <p>code:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  using namespace std;
  char ** fun()
  {
      static char * z = (char*)"Merry Christmas :)";
      return &amp;z;
  }
  int main()
  {
      char ** ptr = NULL;
  
      char ** (*fun_ptr)(); //declaration of pointer to the function
      fun_ptr = &amp;fun;
  
      ptr = fun();
  
      printf("\n %s \n Address of function = [%p]", *ptr, fun_ptr);
      printf("\n Address of first variable created in fun() = [%p]", (void*)ptr);
      cout&lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p>One output example is:</p>
  
  <pre><code> Merry Christmas :) 
   Address of function = [0x400816]
   Address of first variable created in fun() = [0x600e10]
  </code></pre>
  
  <p>So, here the address of function and the address of first variable in function is not same. Why so?</p>
  
  <p>I searched on google but can't come up with the exact required answer and being new to this language I exactly can't catch some of contents on net.</p>