title: C - Convert Integer to Binary Array
body: <p>I am very new to the C language.
  I will need a small program to convert <code>int</code> to binary and the binary preferably stored in an array so that I can further break them apart for decoding purpose.
  I have following:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      int arr[20];
      int dec = 40;
      int i = 0, ArrLen;
  
      if(dec &gt; 0)
      {
          while(dec &gt; 0)
          {
              arr[i] = dec % 2;
              i++;
              dec = dec / 2;
          }
      }
      else
      {
          printf("Invalid Number");
      }
  }
  </code></pre>
  
  <p>From the code above, I can store <strong>the binary</strong> value in <code>arr</code>.
  But instead of getting the binary equivalent: <code>101000</code>, the array now is like <code>{0, 0, 0, 1, 0, 1}</code>, which is the <em>reversed</em> of the correct answer.
  So the question is, how to get an array in the correct order or possibly flip it?
  I have one thing for sure, and that is the maximum array length will not exceed <code>8</code> elements.</p>
  
  <p>This conversion will be used repeatedly.
  So I plan to put it in a function so I'd be able to call the function, pass in an integer, and then get the array as the return value. So another question is, is it feasible to get an array as the return value?</p>