1,523 views

2 Answers

Best answer
4 votes
4 votes

This  code results in the printing of elements alternatively in linked list

suppose 10 || ----> 20 || ------> 30 || ------> 40 || -------> 50 || NULL

prints(10)        head->next->next ------->3rd node

prints(30)        head->next->next ------->5th node

prints(50)        here head->next is null prints(50) and again moves back prints results in reverse

10 30 50 50 30 10


if(head == null)  ---------------- if head is null nothing is done

 return



 

edited by
4 votes
4 votes

First printf will print alternate elements from start to last 

Second printf will print in reverse order , same data which was printed by first printf .

edited by

Related questions

0 votes
0 votes
2 answers
1
Akash Mishra asked Jul 7, 2017
571 views
What is the value of F(n, m)?Function F(n, m : integer) : integer; begin if(n <= 0) or (m <= 0) then F:=1 else F := F(n-1, m) + F(n, m-1); end;
0 votes
0 votes
2 answers
3
Debargha Mitra Roy asked Apr 10
99 views
What is the output of the below code?#include <stdio.h void main() { static int var = 5; printf("%d ", var ); if (var) main(); }a. 1 2 3 4 5b. 1c. 5 4 3 2 1d. Error
3 votes
3 votes
3 answers
4
Laxman Ghanchi asked May 19, 2023
1,157 views
#include<stdio.h void print(int n) { printf("Hello "); if(n++ == 0) return ; print(n); n++; } int main() { void print(); print(-4); }How many times printf execute?? And H...