vendredi 22 juin 2018

C++ function returning string

#include <iostream>

using namespace std;

string test(string s)
{
    string rv = "Hey Hello";
    if(s=="")
        return rv;
    else
        cout<<"Not returning"<<endl;

}

int main()
{
    string ss = test("test");
    cout<<ss<<endl;
}

The above code should not return any value and probably print garbage, but its returning "Hey Hello" even without return statement at the end in test function. Can you tell my why its behaving like this?

Aucun commentaire:

Enregistrer un commentaire