edited by
1,373 views
0 votes
0 votes
struct node{
    int num;
    struct node *next;
}

void print(struct node *ptr)
{
    if(ptr)
    {
        printf("%d",ptr->data);
        do{
            printf("%d",ptr->data);
        }
        while(ptr->next);
    }
}

What is the output, if a $SLL : 1\rightarrow 2\rightarrow 3\rightarrow 4\rightarrow 5$ is passed in the above $C$ code ?

  • Assume Head pointer at Node $1$ 
edited by

4 Answers

1 votes
1 votes
Output : 1 1 1 1 1........

reason : after enetring into while loop the "condition" always become true it is not making progress it is just checking whether next of node1 is their or not which implies true because it is their so it will print 1 "infinite" time.
0 votes
0 votes
i think the answer would be 1111111111111....... infinite time. As the ptr is not incremented.

Related questions

0 votes
0 votes
1 answer
2
kd..... asked Feb 9, 2018
2,006 views
the sorage requirements of a linked stack with n elements will be what
1 votes
1 votes
1 answer
3
kd..... asked Dec 30, 2017
945 views
In a circular single linked list how many external pointers are there because in some books there are two external pointers start pointing at first node and last pointing...