title: How does printf work internally?
body: <p>I am curious as to how <code>printf</code> works internally within Linux. I don't understand how it writes data to <code>STDOUT</code>.</p>
  
  <p>After a bit of searching for the internals, I downloaded <code>glibc</code> and took a look at the source code:</p>
  
  <pre><code>__printf (const char *format, ...)
  {
     va_list arg;
     int done;
  
     va_start (arg, format);
     done = vfprintf (stdout, format, arg);
     va_end (arg);
  
     return done;
  }
  </code></pre>
  
  <p>After finding this, I went deeper into the <code>vfprintf</code> function - but the file is about 2500 lines of unfamiliar C code. I'm looking for an explanation from 10,000 feet of how printf works with a computer's memory and output to display characters on screen.</p>
  
  <p>If I were a piece of assembly code what would I have to do to accomplish the same task? Is it operating system dependent?</p>