Difference between . and ->
Hi there,
I am just trying to learn how to make linked lists and have made the following function:
Code:
list* addList() {
list* firstList = NULL;
list* newList = malloc(sizeof(list));
newList -> count = 128;
newList -> next = firstList;
return newList;
}
This works fine and when I have the following printf statement:
Code:
list* bigList = addList();
printf("%d\n", bigList -> count);
then 128 gets printed out, as I hoped it would.
My question is that when I try the following printf instead:
Code:
printf("%d\n", bigList.count);
then I get an error saying that a struct is required. As I understand it, my addList() function returns a pointer to the list element labeled newList in the function. This list element has a member called count. So why is it that I can't use the membership operator '.' in this case? And what is the essential difference between '.' and '->'?
Many thanks in advance.
Joe