Question: I was searching on how can I print a reverse of linked list and I found this piece of code 

```
/* Function to reverse the linked list */
void printReverse(struct node* head)
{
    // Base case  
    if (head == NULL)
       return;

    // print the list after head node
    printReverse(head->next);

    // After everything else is printed, print head
    printf("%d  ", head->data);
}

```

The problem is that I do not understand the part where it reaches the last pointer which points to NULL and how it comes back one by one and prints the linked list in reverse order.

Is the return statement what makes it go step by step back? Or something else? Please help because I do not understand.

Answer: 
This is a recursive function. Recursive functions work by pushing variables onto the execution stack. The execution order pops off the stack in reverse order from the order it was pushed on the stack. This means that the last execution prints first, then the one previous to that, and so forth until all executions of printReverse print their values.
As others have already explained the recursive version. I suggest you to have a look at this iterative version of printing linked list in reverse order. This is more easy to understand and implement as compared to recursive version, however it increases time complexity.

```
    // To ease testing of code here linked list is created randomly of given size.
    #include<stdio.h>
    #include<cstdlib>
    #include<time.h>
    #define size 10 //Size of list
    struct node
    {
          int info;
          struct node * next;
    };
    typedef struct node* Node;       
    Node start;
    int main()
    {
       int i;
       srand(time(NULL));
       for(i=0;i<size;i++)
       {
          Node ptr;
          ptr=(Node)malloc(sizeof(node));
          ptr->info=rand()%100; //random list is created of given size.
          ptr->next=NULL;
          if(start==NULL)
              start=ptr;
          else
          {
               ptr->next=start;
               start=ptr;
          }
    }
    printf(" Traversal of Linked List in forward direction -\n");
    Node temp=start;
    while(temp!=NULL)
    {
        printf(" %d ",temp->info);
        temp=temp->next;
    }
    printf("\n Traversal of Linked List in backward direction -\n");
    Node ptr=NULL;
    while(ptr!=start)
    {
        temp=start;
        while(temp->next!=ptr)
        temp=temp->next;
        printf(" %d ",temp->info);
        ptr=temp;
    }
       return 0;
    }

```

For more details visit-
<https://github.com/SahdevKansal02/Data-Structures-And-Algorithms.git>