Question:

"C" question. what does the arrow mark(-->) mean in "C"?

by  |  earlier

0 LIKES UnLike

i have an exam tomorrow. tell me please

here is an instance where it is used

int isempty(stack s)

{

if(s->next==null) // i don't know what operation the arrow mark does

return(1);

}

 Tags:

   Report

3 ANSWERS


  1. if next is defined as a pointer, then you use the arrow operator. if next is defined as a normal variable, then you use the dot operator. like this:

    struct s {

    int variable;

    int *pointer;

    };

    .....

    s->pointer // pointer

    s.variable // a normal variable


  2. -> is the structure pointer operator.

    Example:

    struct listNode {

      int val;

      struct listNode *next;

    };

    If you declare one of these:

    struct listNode head;

    you can access its members with the structure member operator . :

    listNode.val = -1;

    listNode.next = NULL;

    If you have declare a pointer to one of these:

    struct listNode *p = &head;

    and want to access its members using p, you use the structure pointer operator -> :

    p->val = 0;

    For s->next == null in your example, s is most likely a pointer to a structure much like what I've shown above, an element of a linked list. Checking for null is the way to determine if the pointer s is referencing the last element of the list.

  3. The arrow is ->, not -->.  On its left is the name of a pointer to a structure or union, and on the right it the name of a member of that structure or union.  In the example you give, the structure is being used to define a linked list, a very common and useful concept among C (and PL/I and assembly language) programmers:

    typedef struct link

    {

    DATA data;

    struct link *next;

    } LINK, *PLINK;

    A doubly linked list—one that can be traversed in either direction—would also declare struct link *previous.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions