title: How to return a pointer in C Language
body: <p>I have a function that returns a pointer and I am making it to compute factorial of a given number.</p>
  
  <p>This is the skeleton code which I can't alter</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  //Read only region start
  
  char* factorial (int input1)
  {
  
      //Read only region end
      //Write code here
  
  
  }
  </code></pre>
  
  <p><strong>The code I wrote is :</strong></p>
  
  <p><a href="https://i.stack.imgur.com/MhZke.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MhZke.png" alt="enter image description here"></a></p>
  
  <p>I tries this code too</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  //Read only region start
  
  char* factorial (int input1)
  {
  
      //Read only region end
      //Write code here
      char fact=1;
      while(input1!=0)
      {
          fact = fact * input1;
          input1--;
      }
      return fact;
  
  }
  </code></pre>
  
  <p>The left side says the question and right side is the code I am writing.
  The error it throws is " <strong>Segmentation fault</strong>"</p>
  
  <p><a href="https://i.stack.imgur.com/x3EhO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x3EhO.png" alt="enter image description here"></a></p>
  
  <p>The program doesn't require <code>main()</code> function cause its something the mettl is using at backend to call the function and evaluate the results.</p>