title: How to print out each bytes' contents in a 4-byte int
body: <p>I designed a C++ code for checking machine's endian. 
  It works well. But, it cannot print out each bytes' contents in a 4-byte int. </p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  bool f()
  {
      int a = 1;
      char *p = (char*)&amp;a;
      for (int i = 0 ; i &lt; 4 ; ++i)
              cout &lt;&lt; "p[" &lt;&lt; i &lt;&lt; "] is " &lt;&lt; hex &lt;&lt; *p++ &lt;&lt; "   ";
      cout &lt;&lt; endl ;
      p -= 4;
      if (*p == 1) return true ; // it is little endian
      else return false;  // it is big endian
  }
  
  int main()
  {
      cout &lt;&lt; "it is little endian ? " &lt;&lt; f() &lt;&lt; endl ;
      return 0 ;
  }
  </code></pre>
  
  <p>output: </p>
  
  <pre><code> p[0] is    p[1] is    p[2] is    p[3] is
   it is little endian ? 1
  </code></pre>
  
  <p>Why the output is empty ?</p>
  
  <p>thanks </p>