title: Usage of %p in printf ?
body: <p>I was reading the following code online from this link : <a href="http://www.cse.scu.edu/~tschwarz/coen152_05/Lectures/BufferOverflow.html" rel="nofollow">http://www.cse.scu.edu/~tschwarz/coen152_05/Lectures/BufferOverflow.html</a></p>
  
  <p>And I was confused about the usage of %p in this line : </p>
  
  <pre><code> printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
  </code></pre>
  
  <p>which is taken from this snippet of code: </p>
  
  <pre><code> /*
    StackOverrun.c
    This program shows an example of how a stack-based 
    buffer overrun can be used to execute arbitrary code.  Its 
    objective is to find an input string that executes the function bar.
  */
  
  #pragma check_stack(off)
  
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt; 
  
  void foo(const char* input)
  {
      char buf[10];
  
      printf("My stack looks like:\n%p\n%p\n%p\n%p\n%p\n% p\n\n");
  
      strcpy(buf, input);
      printf("%s\n", buf);
  
      printf("Now the stack looks like:\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
  }
  
  void bar(void)
  {
      printf("Augh! I've been hacked!\n");
  }
  
  int main(int argc, char* argv[])
  {
      //Blatant cheating to make life easier on myself
      printf("Address of foo = %p\n", foo);
      printf("Address of bar = %p\n", bar);
      if (argc != 2) 
   {
          printf("Please supply a string as an argument!\n");
          return -1;
      } 
  foo(argv[1]);
      return 0;
  }
  </code></pre>
  
  <p>I know %p is the formatter for pointer, but why are there no values following the formatter? What values are actually printed here ? If it is printing the address of the arguments supplied to the foo function, then why there are 5 '%p' and why aren't all the '%p' formatting the same value ? </p>
  
  <p>Thanks a lot. </p>