#include<queue>
using namespace std;
class node {
public:
int data;
node* left;
node* right;
// node(){}
node(int d) {
this -> data = d;
this -> left = NULL;
this -> right = NULL;
}
};
node buildTree() {
cout << "Enter the data: " << endl;
int data = 2;
// cin >> data;
node r(data);
node left(4);
cout<<&r<<endl;
return r;
}
int main()
{
cout<<"print";
node root = buildTree();
cout<<&root<<endl;
return 0;
}
in c++ why local variable address r and main function variable root address are same?
and when i comment left and right data member of node class then it print different!why?
it is output of example why local object (r) of buildtree function and main function object root address are same
it should be different.