title: Fibonacci series using array and pointer
body: <p>The following program is supposed to print fibonacci numbers upto given terms:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int* fibo(int);
  
  int main()
  {
      int num,  *ptr;
      cout &lt;&lt; "How many numbers in fibonacci series? ";
      cin &gt;&gt; num;
  
      ptr = fibo(num);
  
      for (int i = 0; i &lt; num; i++)
      {
          cout &lt;&lt; *(ptr + i) &lt;&lt; " ";
      }
  
  }
  
  int* fibo(int n)
  {
      int arr[50];
      arr[0] = 1;
      arr[1] = 1;
      for (int i = 2; i &lt; n; i++)
      {
          arr[i] = arr[i - 1] + arr[i - 2];
      }
  
      return arr;
  }
  </code></pre>
  
  <p>But it doesn't work. Only the first two elements of fibonacci series are being printed correctly.</p>