title: Casting a character array into an integer
body: <p>EDIT: The wrong type of num2 has been corrected.</p>
  
  <p>Hello,</p>
  
  <p>I have some character arrays of known size which contains raw integer data read from a binary file.</p>
  
  <p>The size of all these arrays have the size of a integer.</p>
  
  <p>I would like to ask whether the following operation is safe and accurate in ALL normal situation, assuming that the endianness of the raw data and the computer running this code agrees.</p>
  
  <pre><code>char arr1[4] = { ... };
  char arr2[2] = { ... };
  
  uint32_t num1 = *static_cast&lt;uint32_t*&gt;(arr1); /* OR num1 = *(uint32_t*)arr1 in C */
  uint16_t num2 = *static_cast&lt;uint16_t*&gt;(arr2); /* OR num2 = *(uint32_t*)arr2 in C */
  </code></pre>
  
  <p>Thank you!</p>