title: pointer to function in c?
body: <p>I m learning c (programming in ANSI c -> fifth edition) and facing the below issue:</p>
  
  <p>I'm implementing one program with pointers to functions</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  //void swap (int *a, int *b);                      //function declaration
  int main() 
  {
    int m = 25;
    int n = 100;
  
    printf("m is %d, n is %d\n", m, n);
    swap(&amp;m, &amp;n);                                    //calling a function
    printf("m is %d, n is %d\n", m, n);
    return 0;
  
  }
  
  void swap (int *a, int *b)                         //function implementation
  {
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
  }
  </code></pre>
  
  <p>in the above program comment the line <code>void swap (int *a, int *b);</code> then program run file but give one suggestion here facing the issue <strong>why here give the  suggestion</strong></p>
  
  <p>main.c:10:3: warning: <strong>implicit declaration of function ‘swap’</strong> [-Wimplicit-function-declaration]<br>
  main.c:16:6: warning: <strong>conflicting types for ‘swap’</strong><br>
  main.c:10:3: note: <strong>previous implicit declaration of ‘swap’ was here</strong><br>
  m is 25, n is 100<br>
  m is 100, n is 25  </p>
  
  <p>when I m uncomment this line <code>void swap (int *a, int *b);</code> then program run fine </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  void swap (int *a, int *b);                      //function declaration
  int main() 
  {
    int m = 25;
    int n = 100;
  
    printf("m is %d, n is %d\n", m, n);
    swap(&amp;m, &amp;n);                                    //calling a function
    printf("m is %d, n is %d\n", m, n);
    return 0;
  
  }
  
  void swap (int *a, int *b)                         //function implementation
  {
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
  }
  </code></pre>
  
  <p>problem is why not allowed this one in the above program</p>
  
  <pre><code>void swap (int, int);              //function declaration
  </code></pre>
  
  <p>and give the error</p>
  
  <p>error: </p>
  
  <p><strong>conflicting types for ‘swap’</strong>
    void swap (int *a, int *b)                         //function implementation</p>
  
  <p>but in book example allowed</p>
  
  <p><a href="https://i.stack.imgur.com/nTWp4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nTWp4.png" alt="enter image description here"></a></p>