title: How can an declare an array in a function that returns an array in c++
body: <p>// functions that converts a number into an array</p>
  
  <pre><code>int *initialiser(int number)
  {
      int array[20];
  
      for (int i = 19; i &gt;= 0; i--)
      {
          array[i] = number % 10;
          number /= 10; // number = number/10
      }
  
      return array;
  }
  </code></pre>
  
  <p>//I get this error</p>
  
  <pre><code>primaryAddSub.cpp: In function 'int* initialiser(int)':
  primaryAddSub.cpp:21:9: warning: address of local variable 'array' returned [-Wreturn-local-addr]
       int array[20];
           ^~~~~
  </code></pre>
  
  <p>I can use static int array[20]; but the function will return the same result each time I call it.</p>