title: Fibonacci numbers - dynamic array
body: <p>I want to write Fibonacci number program, using dynamic array in function. If I want to initialize array in the function, where I must delete this array? Here is code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int* fibo(int);
  
  int main()
  {
      int *fibonacci, n;
      cout &lt;&lt; "Enter how many fibonacci numbers you want to print: ";
      cin &gt;&gt; n;
      fibonacci = fibo(n);
      for (int i = 0; i&lt;n; i++)
          cout &lt;&lt; fibonacci[i] &lt;&lt; " ";
  
      //for (int i = 0; i &lt; n; i++)
          //delete w_fibo[i];
      //delete[] w_fibo;
  
      return 0;
  }
  
  int* fibo(int n)
  {
      int* w_fibo = new int[n];
      if (n &gt;= 0)
          w_fibo[0] = 1;
      if (n &gt;= 1)
          w_fibo[1] = 1;
  
      for (int i = 1; i &lt; n; i++)
          w_fibo[i + 1] = w_fibo[i] + w_fibo[i - 1];
  
      return w_fibo;
  }
  </code></pre>