typedef struct node int number struct node next Node void

typedef struct node
{
    int number;
    struct node * next;
} Node;

void printout(Nodeptr head)
{
    int i=0;
    while(head!= NULL)
    {
        printf(\"Node #%d contains %d \ \", i, head->number);
        head=head->next;
        i++;
    }
}

How do I call the function \'printout\' in the main?

WHat would be the prototype of \'printout\'?

Solution

Here given that typdef struct node as Node hence there is no need of writing struct node all the time. This is the usage of typedef keyword. Now based on the above program it contains a function printout(Nodeptr head) in which Nodeptr is of type of struct node i.e., typedef struct node Nodeptr but already Node has been typedef we can use typedef Node Nodeptr statement to make Nodeptr as struct node

Now the code in main method will be:

typedef Node Nodeptr; //typedef of struct node to Nodeptr

main()

{

Nodeptr head;

head.number=5;

head.next=NULL;

printout(head); // call the function printout(Nodeptr head)

}

Now the declaration(prototype) of printout function will be:

return type is void since no return value and with one parameter of type struct node which was typedef as Nodeptr ...

void printout(Nodeptr ); //prototype of function printout...

typedef struct node { int number; struct node * next; } Node; void printout(Nodeptr head) { int i=0; while(head!= NULL) { printf(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site