I have these two functions:
void MakeNull_List(List L){
L->Last=0;
}
void Empty_List(List L){
return L.Last==0;
}
So, can anyone explain this code for me? What is the difference between L->Last
and L.Last
?
I have these two functions:
void MakeNull_List(List L){
L->Last=0;
}
void Empty_List(List L){
return L.Last==0;
}
So, can anyone explain this code for me? What is the difference between L->Last
and L.Last
?
I hope that this code does NOT come from your lecturer, otherwise you should look for another one...
Sadly this code doesn't make sense because it is wrong! But I think you meant the following:
void MakeNull_List(List *L){ //* added
L->Last=0;
}
bool Empty_List(List L){ //changed to bool
return (L.Last==0); //Please also use brackets here
}
The first function sets the last element to 0 (NULL) whathever sense it should make?!? The second function checks whether the last element is 0 (NULL) or not.
And your actual question: ->
is used to Access properties of a pointer to an object and .
accesses the properties directly of the object. For more info read here
Then you access object by variable or reference you should address to it fields by .
.
Then you have a pointer to object you should previously dereference it. So, you can write (*ptr).someField
or ptr->someField
.
I think, you miss *
in void MakeNull_List(List *L)
definition.