linked lists and pointers clarify

closed account (4ET0pfjN)
let's say I'm building a BST (binary search tree) w/ node as such:

1
2
3
4
5
6
7
8
9
10
11
12
13
struct bst_node//Binary search tree node
{
 int data;
 bst_node* left;
 bst_node* right;
};

int main()
{
 bst_node* root = NULL;
 
 return 0;
}


So for outputs for point 3, I sort of understand why it doesn't work when we use dereference operator...:
1) if it was: cout << root << endl;//This would be address of what pointer root pts to which is address 0

2) if it was: [code]cout << &root << endl;//This would be the address of the the declared root pointer itself since a pointer is a variable and it takes up space so it must exist somewhere in memory

3) if it was: [code] cout << *root << endl;//program crashes, is this b/c a root is not exactly a pointer...I'm not sure how to explain so that's why we have to use right arrow operator to access members: data, left, right.
This statement

cout << *root << endl;

shall not be compiled because the operator << was not defined for the type struct bst_node.

If to accept that this operator was defined then *root shall be valid object that is it shall be defined in the memory.
closed account (4ET0pfjN)
Can you clarify a little more
What do you want to know?
closed account (4ET0pfjN)
I thought it was b/c of the fact that a bt_node is a special pointer for the way I'm using it but I guess I shouldn't go too deep into details unless it's useful as a programmer, I don't want to get into history I mean...so I'll leave it at that,thanks
Last edited on
Topic archived. No new replies allowed.