title: Self-defined factorial function without return statement
body: <pre><code>#include&lt;iostream&gt;
  
  using namespace std;
  
  int fac(int n){
    int j{1};
    for (int i =1 ; i &lt;=n; ++i){
      j *= i;
    } // return j;
  }
  
  int main(){
  cout &lt;&lt; fac(8)&lt;&lt; endl;
  return 0;
  }
  </code></pre>
  <p>While I run this code without the <code>return j</code> statement (just trying to see what will happen), although the answer is wrong, I noticed an interesting phenomenon. Regardless of the compilers I used, I noticed that the wrong answer given is always &quot;9&quot;. At first, I suspect the number comes from the number of time the loop ran but changing the value of the initializer still yield the same answer. Only if you are feeding the initializer with a number larger than 8 (i.e. 100) then the output will be that number you used for the initializer.</p>
  <p>I know that without a return statement is undefined behaviour, which might result in unexpected results. But why are the results from different compilers consistent? I was expecting random results to show up by using different complier.</p>