I have something that I don't know how to use the Pointer, this is my code:
struct node{
int data;
struct node* next;
}
struct node* BuildWithLocalRef() {
//give a list with: 1 2 3 4 5
//and your work is import this list in to Linked List with that order
//so linked List after finish will have:
//1-2-3-4-5
struct node* BuilList(){
struct node* head = NULL;
struct node** lastPtrRef= &head;
int i;
for (i=1; i<6; i++) {
Push(lastPtrRef, i); //give new element with value i into Linked List and before lastPtrRef node.
lastPtrRef= &((*lastPtrRef)->next);
}
// head == {1, 2, 3, 4, 5};
return(head);
}
In that above code, there are 2 points that I don't know:
1)at line,
struct node** lastPtrRef=&Head
: I don't know what this line mean. I often use:
struct node** lastPtrRef=*Head
to point what *Head point.
2) at line,
lastPtrRef= &((*lastPtrRef)->next);
maybe I met same problem above, that I don't know use "&(*....) mean.
with my knowledge, "&" operator to take some one address. but I don't know the different purpose of two type of declare: with above example is:
struct node** lastPtrRef=*Head;//type 1
struct node** lasPtrRef=&Head; //type 2
so, who know this problem, please answer for me, please. many things in pointer that I don't know although I read basic document about Pointer :(
thanks for tons :)