I m studying Binary Search Tree just had little Doubt, here is struct to construct a node.
struct Node
{
int data;
Node* left, *right;
};
Now My doubt is when I m creating a new node why do I have to write
Node* node =new Node;
Why not
Node* node;
Node* node;
You define a pointer, but the pointer points to nothing.
Node* node =new Node
You define a pointer and a Node object, and make the pointer point to the object.
Node* node
this is a pointer which is just declared.
Accessing this pointer may give your garbage.
If you want to make pointer point to your own node object , you do by
Node* node = new Node;
Hope this clears!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.