在下面的代码中,函数内手动分配的内存不应该在heap中不会被自动释放吗,为什么最后在主程序中的两个cout为空呢
#include<bits/stdc++.h> using namespace std; class test { public: int val = 1; }; void fun(test* t) { t = new test(); cout << t->val << " " << t << "\n"; } void func(char* a) { a = new char('a'); cout << *a << " " << a << "\n"; } int main() { char *a = NULL; func(a); test *b = NULL; fun(b); cout << "-----\n"; cout << *a << " " << a << "\n"; cout << b->val << "\n"; }
全部评论
(0) 回帖