Why is it bad practice to return a pointer to a local variable or parameter? [duplicate]
问题 This question already has answers here : How to access a local variable from a different function using pointers? (9 answers) Closed 6 years ago . I found this question on my study guide, and I am not sure why it would be bad to return a pointer to a local variable/parameter. Any ideas? 回答1: It's not so much a "bad practice" (implying that it might cause problems) as much as it is a practice that will absolutely cause undefined behavior . It's like dereferencing a null pointer: don't do it