title: problem in creating a non standard link list
body: <p>I finished learning object oriented programming (basics only) and started to learn link list and I got to know it consists of nodes which consists of data and a pointer to next node.</p>
  <p>In the following code, I have tried to create 5 objects of class node , each of which has two attributes - data and pointer to other object. I tried to attach nodes using a function attach as shown. And in the end , I intend to recursively print the data from last node i.e. arr[4] to first node i.e. arr[0]. Since only the first node has a null pointer in its attribute next, idea was that the recursion would stop at first node. But , the output shows that arr[4] has a null pointer in it's member next.<br />
  I'm not able to find where am I going wrong.</p>
  <blockquote>
  <p>Input : 4 3 2 1 0</p>
  <p>Output : 4</p>
  <p>Output that I expect : 0 1 2 3 4</p>
  </blockquote>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  class node
  {   public:
      int data;
      node *next;
  };
  void attach(node &amp;s1,node &amp;s2)
  {
      s1.next=&amp;s2;
  }
  void print(node &amp;source)
  {
      cout&lt;&lt;source.data&lt;&lt;&quot; &quot;;
      if(source.next)         return; 
      else                    print (*(source.next));
  }
  int main()
  {
      int n{5};
      node arr[n];
      cin&gt;&gt;arr[0].data;
      arr[0].next=nullptr;
      for(int a=1;a&lt;n;++a)
      {
          cin&gt;&gt;arr[a].data;
          attach(arr[a],arr[a-1]);
      }
      print (arr[4]);
  }
  </code></pre>