가능한 중복 : 당신이 심판을 반환 할 때
Returning the address of local or temporary variable
Can a local variable's memory be accessed outside its scope?
return reference to local variableref를 반환하면 정의되지 않은 동작입니까? 지역 변수에?
은 정의되지 않은 동작이 그것입니다. 지역 변수에?
int & func(){
int x = 10;
return x;
}
int main() {
int &y = func();
cout << y << endl;
}
나는 "지역 변수는"사양에서 특별한 의미가 있는지 모르겠지만, 나는 그것이 정적 저장 기간없이 지역 변수에 대한 정의되지 않은 동작이 될 것 상상한다. –