title: How does call stack work with recursion with or without return type?
body: <p>I noticed that some recursions have a return type but some are just having void as the return type. I can't tell when to use which. I also looked into the call stack and I guess the recursions with a 'void' type is just returning the value recorded on the stack. I don't know if my understanding is correct.
  I can't convert a recursion with void return type into a recursion a return type. For example, I don't know how to implement the Fibonacci function with the void return type.</p>
  <pre><code>private int fibonacci(int number) {
  
              if (number &lt; 1) {
                  return number;
              }
              return fibonacci(number-1)+fibonacci(number-2);
          }
  </code></pre>
  <p>Also, in the rec function, I investigated the call stack; but I can't tell how does the program knows when to pop a record on the stack. In the base case of the rec function, the program works perfectly fine without the 'return;'; but I noticed that it also works with the 'return;'. I really can't tell why it is like this. Can someone please explain how does the stack work with the recursion?</p>
  <pre><code>private static void rec(int l, int r, List&lt;String&gt; list,String s){
          if(r==0){
              list.add(s);
  //            return;
          }
  
          if(l&gt;0){
              rec(l-1,r,list,s+&quot;(&quot;);
          }
          if(r&gt;l){
              rec(l,r-1,list, s+&quot;)&quot;);
          }
      }
  </code></pre>