valgrind error “Invalid read of size 4” [duplicate]
问题 This question already exists : c++ warning: address of local variable Closed 6 years ago . Here is my program int* fun1(void) { int n=9; int *pf=&n; cout<<*pf<<endl; return pf; } int main(int argc, char *argv[]) { int *p=fun1(); cout<<*p; return 0; } Compilation and running of program doesn't give any problems but with valgrind it gives message/warning "Invalid read of size 4". Any help to resolve the warning is most welcome 回答1: n is a local variable in fun1() and is no more valid after exit