title: C/Unix Strange behaviour while using system calls and printf
body: <p>I'm a newbie, trying to <em>really</em> understand systems programming. In the following program, I'm reading a file called 'temp1' (containing 1 2 3 4) and printing its contents to stdout. However, I also wanted to check the value of file descriptor returned by open. If I include the '\n' in printf call on line 5, the output prints value filep first and then contents of file. But if I remove the newline, the contents of file get printed first and then the value of filep.
  Why would this happen ? </p>
  
  <pre><code>     int main(){
       char buf[BUFSIZ];
       int n, filep;
  
       // Open the file
       filep = open("temp1", 'r');
       printf("%d\n", filep); // the newline alters program behaviour
  
       while((n=read(filep, buf, BUFSIZ)) &gt; 0)
           write(1, buf, n);
       return 0;
      }
  </code></pre>
  
  <p>I am using gcc 4.6.3.</p>