title: Cast int as byte array in C++
body: <p>I am trying to use implement the LSB lookup method suggested by Andrew Grant in an answer to this question: <a href="https://stackoverflow.com/questions/757059/position-of-least-significant-bit-that-is-set">Position of least significant bit that is set</a>  </p>
  
  <p>However, it's resulting in a segmentation fault. Here is a small program demonstrating the problem:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  typedef unsigned char Byte;
  
  int main()  
  {  
      int value = 300;  
      Byte* byteArray = (Byte*)value;  
      if (byteArray[0] &gt; 0)  
      {  
          std::cout&lt;&lt; "This line is never reached. Trying to access the array index results in a seg-fault." &lt;&lt; std::endl;  
      }  
      return 0;  
  }  
  </code></pre>
  
  <p>What am I doing wrong?<br>
  I've read that it's not good practice to use 'C-Style' casts in C++. Should I use <code>reinterpret_cast&lt;Byte*&gt;(value)</code> instead? This still results in a segmentation fault, though.</p>