double astrix pointer question..

This is a discussion on double astrix pointer question.. within the C Programming forums, part of the General Programming Boards category; what this function does? Double astrix says that the parameter is the pointer which P points at so the parameters ...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    double astrix pointer question..

    what this function does?

    Double astrix says that the parameter is the pointer which P points at
    so the parameters is p->next and num.
    They create a node called elt ,they assign it a memory space in a size node
    and make it a node pointer.
    next they say that elt->next=p->next
    elt->value is num
    and p->next=elt


    I cant imagine what is the structure of the combination of those to marked red lines.
    ??
    Code:
    typedef struct node {
        int value;
        struct node *next;
    }Node;
    
    void what1(Node ** p,int num){
       Node *elt;
       elt=(Node*)malloc(sizeof(Node));
       elt->next=*p;
       elt->value=num;
       *p=elt;
    }

  2. #2
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    pass by reference anyone?
    Just GET it OFF out my mind!!

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by transgalactic2 View Post
    what this function does?

    Double astrix says that the parameter is the pointer which P points at
    so the parameters is p->next and num.
    The parameter is a pointer that points to the pointer which points to a Node. The ** means a pointer to a pointer.
    So the parameter is p and num.
    There is also a pointer which p points at. Lets call it nodePtr. There is also a node in which nodePtr points to. Lets call it node.

    You have this:
    p -> nodePtr -> node

    So:
    elt-> next = *p means: elt->next = nodePtr
    *p = elt means: nodePtr = elt

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by audinue View Post
    pass by reference anyone?
    In C?

    What I think you want is
    Code:
    (*p)->next
    If I understand you correctly.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    It basically takes the address of a pointer to which it assign malloced memory. Only a pointer can store an address, so there you go.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    I think EVOEx is on the mark if I understand your question. p is a pointer to pointer to a Node while *p is a pointer to a Node object as in
    Code:
    elt->next=(*p)->next 
    (*p)->next=elt

  7. #7
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    what means Node **p in the signature??

    p->next ?(a pointer which points to a pointer)

    am i correct?

  8. #8
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    p isn't the same as p->next if that is what you mean. I answered what p means in post #3.

    It is indeed a pointer that point to a pointer. So its value (*p) is a pointer that points to a node. So p points to a pointer which pointer points to a node.

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    Quote Originally Posted by transgalactic2 View Post
    what means Node **p in the signature??

    p->next ?(a pointer which points to a pointer)

    am i correct?
    Node** means it is a pointer to a variable of type Node*. It can be no more simple than that.
    And the "p->next" syntax just means "(*p).next", and since *p is a Node*, it is illegal.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    so **p point to a Node * type variable

    what point to what during this function (in every step)

    ??

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    Quote Originally Posted by transgalactic2
    so **p point to a Node * type variable
    No, if p is a Node**, then **p is a Node.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    but what is the stucture of **p regarding a linked list system.

    I cant imagine what points to what in every step during the running of this function.
    Code:
    typedef struct node {
        int value;
        struct node *next;
    }Node;
    
    void what1(Node ** p,int num){
       Node *elt;
       elt=(Node*)malloc(sizeof(Node));
       elt->next=*p;
       elt->value=num;
       *p=elt;
    }

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    Quote Originally Posted by transgalactic2
    I cant imagine what points to what in every step during the running of this function.
    What exactly is the part that you cannot understand?

    Look, you have to try and explain what the function does. If you cannot fully explain it, at least show some effort by explaining these two lines:
    Code:
    Node *elt;
    elt=(Node*)malloc(sizeof(Node));
    Then try to explain what this line does:
    Code:
    elt->next=*p;
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    I dont know what it does.
    I was asked to explain what it does.
    i can guess but this doble astrix thing and linked list
    i dont know whats happening in the linked list when the double astrix involved.

    Code:
    typedef struct node {
        int value;
        struct node *next;
    }Node;
    
    void what1(Node ** p,int num){
       Node *elt;
       elt=(Node*)malloc(sizeof(Node));  //create a node called elt ,assign it some memory
       elt->next=*p;     //from this point i dont know what the effect of the double astrix
       elt->value=num;
       *p=elt;
    }

  15. #15
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    Okay, at least you got the first part. Now, what is the type of elt->next? What is the type of *p?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 1 of 7 1234567 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about pointer arithmetic and types
    By brooksbp in forum C Programming
    Replies: 4
    Last Post: 08-22-2008, 01:53 PM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 05:54 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21