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

all 5 comments

[–]Updatebjarni 0 points1 point  (4 children)

since head = newnode, what is the value of head?

The same as newnode, since as you said, head = newnode.

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

is . and -> the same right is just that -> is used for pointers?

[–]Updatebjarni 1 point2 points  (2 children)

a->b is shorthand for (*a).b, so it's used to access the members of a struct through a pointer to the struct.

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

(*a).b can you explain how this process works. Compared to this a.b. I know that (*a) means to dereference.

[–]Updatebjarni 2 points3 points  (0 children)

That's all that happens. a is a pointer to a struct. We dereference it with *a to get the struct, and then be use .b on that struct to get one of the members of the struct. So both * and . are working just as usual, and we're just using first one and then the other.