Why output differs if i erase "else" from the function? : <p>I am trying to write a GCD function to calculate gcd of two integers using euclids algorithm. In the function if i erase "else" it outputs 3 which is incorrect . But if i use "else" it outputs 1 which is the correct output. i assume if i don't use "else" the function is still correct. Why am i getting  two different outputs.</p>

<p>Here is my code, </p>

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

using namespace std;


int euclidGcd(int x , int y){

    if(x%y!=0)
        euclidGcd(y , x%y );
    else
        return y;

}

int main(){

    cout&lt;&lt;euclidGcd(2,3)&lt;&lt;"\n";


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