title: How to print the return value of a function using printf()?
body: <h2>Update:</h2>
  
  <p>The original code looked a lot like this:</p>
  
  <pre><code>// printf(printf(););
  
  #include &lt;string&gt;
  
  int main()
  {
     printf(printf("Hello, WORLD!"););
  }
  </code></pre>
  
  <p>However, in the original post, <code>printf("Hello, WORLD!")</code> was assigned to a variable, x.</p>
  
  <h2>Intended questions:</h2>
  
  <ol>
  <li>How do I call the return value of a function within a function?  As a beginner, learning to reference a string variable using %s, I wondered how to reference a the return value of a function (for example, if the return value were a string, would I still use %s).  </li>
  <li>What does "called to print" mean?  I think a simplistic explanation is: the string is put into memory and assigned an address, and the class definition tells the compiler to look up the location in memory based on the class's input-argument definition; so, the address in memory is called to print by the compiler.</li>
  <li>Is the first argument of <code>printf()</code> also the return value of <code>printf()</code> such that <code>x == "Hello, World!"</code> is true in <code>x = printf("Hello, World!")</code>?</li>
  </ol>
  
  <h2>Original post:</h2>
  
  <p>I'm looking at <a href="http://www.cplusplus.com/reference/cstdio/printf/" rel="nofollow noreferrer">http://www.cplusplus.com/reference/cstdio/printf/</a></p>
  
  <p>it says: <code>int printf ( const char * format, ... );</code>, but it doesn't define <code>...</code>.  So, I don't know what <code>...</code> is referencing.  I wrongly assumed that meant <code>( const char * format, const char * format, const char * format, ~</code>.  But in fact, I can't decipher the meaning based on guessing and reading.</p>
  
  <p>Using this program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main(int argc, char ** argv)
  {
      str x = printf("Hello, World!\n");
      printf("x has %d characters.\n", x);
      //"x has %d characters.\n" appears first, x appears second.
  
      return 0;
  }
  </code></pre>
  
  <p>We see the result:</p>
  
  <pre><code>Hello, World!
  x has 14 characters.
  </code></pre>
  
  <p>When I expected:</p>
  
  <pre><code>x has 14 characters.  //because this appears first.
  Hello, World!         //because this appear second.
  </code></pre>
  
  <p>Because <code>x</code> comes after <code>x has 14 characters.</code>.</p>
  
  <p>Someone please explain why <code>./a.out</code> is giving me the results in backwards order (using gcc and shell in Ubuntu); furthermore, eclipse is shown to give the results in this same backward order.</p>
  
  <p>Perhaps another way to rephrase the question would be: <strong>where is <code>"Hello, World!\n"</code> being called to print?</strong></p>