struct node
{
int data;
struct node *next;
};
What is difference between following two functions:
void traverse(struct node *q)
{ }
and
void traverse(struct node **q)
{ }
How can i call above functions from main program?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first argument list passes a pointer to a
struct node. This allows you to change thestruct nodein the body of the function. For instance:The second argument list passes a pointer to a pointer to a
struct node. This allows you to not only change thestruct nodein the body of the function, but also to change what the pointer points to. For instance:As for calling the two versions of the function, from
mainor otherwise: given a pointer to your structure:struct node *arg;,traverse(arg);traverse(&arg);Alternately, given a structure declared as
struct node arg;, you can make a pointer to it:And then:
traverse(&arg);traverse(&ptrToArg);