C + + member variable release problem

CSDN Q & A 2022-05-15 04:40:25 阅读数:778

membervariablereleaseproblem
The phenomenon and background of the problem

I'm a beginner
Just look at the b One of the stations c++ course
The following figure is what he said

img

But I tried it myself, and the result was different from what he said ..

img

img


What's the reason , Is that tutorial wrong

Operation results and error reporting contents
My solution ideas and tried methods
What I want to achieve



Take the answer :

That's right! , It's time to show me
Code :

#include<iostream>using namespace std;int* fun() { int a = 10; return &a;}int main(){ int* p = fun(); cout << *p << endl; cout << *p << endl; cout << *p << endl;}

result

img


版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。 https://primo.wiki/2022/131/202205041916555281.html