Code Blocks incorrect c++ output
<p>I have the following code:</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

Sum (int a, int b)
{
    int x = a - b;
    //cout &lt;&lt; x &lt;&lt; " \n";
    return x;
}

int main()
{
    int s1 = Sum(3, 6);
    cout &lt;&lt; s1;

    return 0;
}
</code></pre>

<p>System info:
<em>Win 7 Sp1 x64 Ultimate/Professional or Win 8.1 x64
Code Blocks 16.01 MinGW
Debugger name and version: GNU gdb (GDB) 7.6.1
compiler: GNU GCC Compiler</em></p>

<p>This code compiles with no problems, but this IS the problem, there should be errors.</p>

<p>1) Function Sum, has no return value, on <a href="http://cpp.sh/" rel="nofollow noreferrer">http://cpp.sh/</a> it doesn't let me compile because of this.</p>

<p>2) Variable's s1 value is -3 whether I write "return x" or not. </p>

<p>It somehow passes the value of <code>x</code> everytime BUT if I uncomment the <code>cout</code> statement above the "<code>return x</code>" everything starts to work out as expected, what the hell :) --> <code>s1</code> will have a random value when no return statement is in place (because it was not initialized prior to being used for the function call) and -3 when the <code>return</code> is there.</p>

<p>I've tried this on 3 separate computers and they all exhibit the same behaviour. So I don't think the machine is the problem. 
I also tried using a different compiler but I don't know if I configured them correctly and they don't have a debugger right ? I tried <em>Borland c++</em> and <em>Digital Mars</em>. <em>Borland</em> has a new version 10.1 instead of the 5.5 that codeblocks supports and I couldn't make the new one work.
I don't even know if this is a compiler or program issue ?</p>

<p>I'm trying to learn C++ and this is very annoying. Our teacher is using the same software in class but on <em>Linux</em> and it works perfectly.</p>

<p>Off topic: Is there a way to insert code with line numbers here ? First post here so i'm still new at this :). </p>

<p>Thank you !</p>