The problem of return reference to local variable

Posted by skydoor on Stack Overflow See other posts from Stack Overflow or by skydoor
Published on 2010-03-21T19:04:56Z Indexed on 2010/03/21 19:11 UTC
Read the original article Hit count: 374

Filed under:

I happened to find this code return 5. It's OK to write it this way or should definitely be avoid?

   int& f() {

     int i = 5; 
     return i;
}

int main(){

    cout<<f()<<endl;    
}

© Stack Overflow or respective owner

Related posts about c++