title: Compile and run program without main() in C
body: <p>I'm trying to compile and run following program without <code>main()</code> function in <code>C</code>. I have compiled my program using the following command.</p>
  
  <pre><code>gcc -nostartfiles nomain.c
  </code></pre>
  
  <p>And compiler gives warning</p>
  
  <pre><code>/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400340
  </code></pre>
  
  <p>Ok, No problem. then, I have run executable file(a.out), both <code>printf</code> statements print successfully, and then get <strong>segmentation fault</strong>. </p>
  
  <p>So, my question is, <strong>Why segmentation fault after successfully execute print statements?</strong></p>
  
  <p>my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void nomain()
  {
          printf("Hello World...\n");
          printf("Successfully run without main...\n");
  }
  </code></pre>
  
  <p><strong>output:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>Hello World...
  Successfully run without main...
  Segmentation fault (core dumped)
  </code></pre>
  
  <p><strong>Note:</strong> </p>
  
  <p>Here, <code>-nostartfiles</code> gcc flag prevents the compiler from using standard startup files when linking</p>