Doubt in the following code

node* levelbuild(){
int d;
cin>>d;
node * root=new node(d);
queue<node*> q;
q.push(root);

while(!q.empty()){
    node *n = q.front();
    q.pop();
int c1,c2;
cin>>c1>>c2;
if(c1!=-1){
    n->left=new node(c1);
    q.push(n->left);
}

if(c2!=-1){
    n->right=new node(c2);
    q.push(n->right);
}
 }
 return root;

}
In the above code when we write node *n = q.front(); Basically we are pointing n to the node to which root was already pointing. So whater changes we make to n are reflected in root also. I am right??

n is the pointer of type node
and q.front is also a pointer of type node

here we just assign the value of q.front() to n

yes…thats what I am saying that now both root and n points to same data in memory and any changes made to n will reflect to root also.

yes, both pionts to same location in a memory hence changes reflect

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.