Link to home
Start Free TrialLog in
Avatar of GPicasso
GPicasso

asked on

What does this mean in C?

return L->Next == NULL;

Most specifically what does
->

Open in new window

do

I expect this is extremely basic
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of farzanj
-> is the equivalent of (*L).Next.  

In C, a variable (x) of a struct (A) is accessed by A.x

Now if you have a pointer (B) to the struct, you have to use (*B).x or B->x
As for_yan said, L is a pointer to a structure.  You would find out which structure by finding the declaration for L.  In this case, I would guess that this function is processing a linked list (or similar).  Here's an example (untested).

typedef Node
{
    Node *link;
    char item [ 50 ];
} Node;

int isLastElement ( struct Node *L )
{
    return L->next == NULL;
}

main()
{
   ...
   if ( isLastElement ( &Node ) )
        printf ( "We are at the last element\n" );
    ....
}

Open in new window


farzanj just said what I was going to put in my next post.  He is correct as well.
Avatar of GPicasso
GPicasso

ASKER

Ok so like if I have a struct named L

->L is like *L  
meaning it returns the address of L... correct?
Next should be another field of the structure that give the address of the next estructure data, this type of definition is used to create a linked list.  *L = address of the current node of the structure
L->next = address of the next node of the structure

check the following
http://gd.tuwien.ac.at/languages/c/programming-bbrown/c_086.htm 
Evilrix, I don't know where the repeat comes from.  If it's me, it's one of my tutoring methods that's been successful in getting to the "Oh....I see" moment.  It doesn't work for everyone.  It works for some students.

Picasso, L-> is like (*L).  Please look at farzanj's post again.  Then look at my first post with code.  Replace line 9 with

    return (*L).next == NULL;

Open in new window


Mostly L-> is easier to type and read.

sonagu's reference is very good if you need/want help understanding Linked Lists.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Evilrix, my apology if I repeated/re-worded the previous post, although I never though it was against EE policy and if it is please quote it.