# C++:指针的引用
记录一下刷题时,找了很久的一个bug,函数中对输入指针进行操作TreeNode* &node
#include<bits/stdc++.h>
using namespace std;
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};
void createTree(TreeNode* &node){
node=new TreeNode(0);
cout<<" node in function: "<<node<<endl;
node->left=new TreeNode(12345);
node->right=new TreeNode(54321);
}
int main(){
TreeNode* root=NULL;
cout<<" root before : "<<root<<endl;
createTree(root);
cout<<" root after : "<<root<<endl;
return 0;
}
/* output
root before : 0
node in function: 0xfb17a0
root after : 0xfb17a0
*/