"I was trying to assign NULL
to a pointer root in a function. But it doesn't really get assigned by NULL
using function. But when I tried to assign root = NULL
in main it get assigned. I am not getting why it happens so?
#include<bits/stdc++.h>
using namespace std;
struct node{
int key;
};
void deletion(struct node* root){
root=NULL;
}
void print(struct node* temp){
if(!temp)
return;
cout<<temp->key;
}
int main(){
struct node* root = new struct node;
root->key=10;
cout<<"Initially : ";
print(root);
deletion(root);
cout<<"\nAfter deletion() : ";
print(root);
root=NULL;
cout<<"\nAfter assigning in main() : ";
print(root);
}
The output I am getting is :
Initially : 10
After deletion() : 10
After assigning in main() :