+ 4
Linked List in C
Im trying to create Linked list in c language and I have this unexpected result when I'm trying to add an element at the beginning of the List. Can you find my mistake? Here is my code: https://code.sololearn.com/c62w8vcJnb8R/?ref=app
8 odpowiedzi
+ 8
David Carroll check out the number of comments in Gordie [#observer_status_only] 's code. I suppose they have a place in explaining code to someone who needs more understanding? What do you think?
+ 7
Sonic The use of code comments in code used for instructional purposes or for a learner to preserve their thoughts is 100% appropriate. 😉👌
+ 6
If you use 1 * you create a copy of the pointer. If you make it point somewhere else in the function, which you are doing here, it is not reflected outside the function.
The 1st * is there for the type itself (node_t*) and the 2nd * is there for the address of the pointer.
So no, it's either ** and & or * and return the head.
+ 5
SPush(head, 14); should be SPush(&head, 14);
Some people choose to return the head so you can avoid the & and the **.
+ 4
Yea, that's what pointers do to you.
Try not to overthink it.
It's just an integer that uses different CPU instructions.
You'll get the hang of it if you use it alot. :)
+ 3
Can I simply change the ** to * and avoid the &, will be the save work done?
+ 3
It's a little bit tricky to my mind...
+ 3
I'm trying to understand them by writing every variable and every pointer on a paper and it's value and the variable it is pointing to.