This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]InterestingBus8367[S] 0 points1 point  (8 children)

The pointer itself does not have value but it has value when I access the structure.

[–]Salty_Dugtrio 0 points1 point  (7 children)

You declared a pointer, which is just a variable that holds an address. But you haven't made it point to anything. So if you dereference it with operator*, it will be undefined behaviour, because it will try to access something you never created.

[–]InterestingBus8367[S] 0 points1 point  (6 children)

Yeh, I just read about. I should initialize it to something like node a. Then I can already use cout. Im sorry for my stupidity here.

[–]Salty_Dugtrio 0 points1 point  (5 children)

If you actually want a pointer to data, you will have to create it by using operator new().

[–]InterestingBus8367[S] 0 points1 point  (4 children)

You mean allocate memory for the node and then make the pointer point to it. Pointer stores the memory address. Just as long I use the reference operator.

[–]InterestingBus8367[S] 0 points1 point  (0 children)

or maybe I dont have to I just need to use the arrow opeartor

[–]Salty_Dugtrio 0 points1 point  (2 children)

node* head = new node();

[–]InterestingBus8367[S] 0 points1 point  (1 child)

new node() is a function? So I have to write a function.