title: Why am I getting segmentation fault error?
body: <p>I am writing a C ++ program that needs to convert numbers from decimal to binary. Here is my code:</p>
  <pre><code>int* convertToBinary(int i, unsigned int n) {
      int ans[10000];
      if (n / 2 != 0) {
          convertToBinary(i + 1, n / 2);
      }
      ans[i] = n / 2;
      return ans;
  }
  
  void send_number(int num) {
      
      for (int j = 0; j &lt; 16; j++) {
          printf(&quot;%d&quot;, convertToBinary(0, num)[j]);
      }   
  }
  </code></pre>
  <p>In this case, the <code>num</code> variable takes only natural values from 0 to 65535.</p>
  <p>The main function is <code>send_number()</code>.</p>
  <p>On execution I get the 'Segmentation fault (core dumped)' error. I can't figure out why this is happening.</p>
  <p>PS: I am C++ beginner. I don't know English well and use google translator</p>