title: Using printf with a pointer to float gives an error
body: <p>When I try to compile this code:</p>
  
  <pre><code>void main()
  {
  float x;
      x=6.5;
      printf("Value of x is %f, address of x %ld\n", x, &amp;x);
  }
  </code></pre>
  
  <p>it gives me this error:</p>
  
  <p>pruebaso.c: In function ‘main’:</p>
  
  <p>pruebaso.c:5:9: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]</p>
  
  <p>printf("Value of x is %f, address of x %ld\n", x, &amp;x);</p>
  
  <p>^</p>
  
  <p>pruebaso.c:5:9: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘float *’ [-Wformat=]</p>
  
  <p>I've seen in another forum the solution is to make a cast to a void pointer first:
  <a href="http://www.linuxquestions.org/questions/programming-9/beginning-c-programming-how-to-print-memory-locations-printf-conversion-number-927305/" rel="nofollow">http://www.linuxquestions.org/questions/programming-9/beginning-c-programming-how-to-print-memory-locations-printf-conversion-number-927305/</a></p>
  
  <p>But making this change,</p>
  
  <pre><code>printf("Value of x is %f, address of x %ld\n", (double)x, (void *)&amp;x);
  </code></pre>
  
  <p>now gives me a warning:</p>
  
  <p>pruebaso.c: In function ‘main’:</p>
  
  <p>pruebaso.c:5:9: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]</p>
  
  <p>printf("Value of x is %f, address of x %ld\n", (double)x, (void *)&amp;x);</p>
  
  <p>^</p>
  
  <p>pruebaso.c:5:9: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘void *’ [-Wformat=]</p>
  
  <p>Could someone explain me how could I solve it without getting a warning?</p>
  
  <p>Thank you</p>