title: 1) Create dynamically filled array in a function. 2) Return the array content
body: <p>I was doing a prime no# class (runs a function to check if inout is prime) and tried to take it a little further by printing what the prime numbers are for inputs that are prime. I managed to hack together an inelegant solution as you can see in the code, by wedging a for-loop in the middle of a cout.</p>
  <p>I want to write a function that would create an array of all numbers that input num can be divided by, and then call the function in my main func.</p>
  <pre><code>int main() {
      
      int num;
      
      cout&lt;&lt;&quot;Enter a number and we'll check if it's prime: &quot;;
      cin&gt;&gt;num;
      
      isPrime(num);
      
      if (isPrime(num) == true)
          cout&lt;&lt;&quot;Number is prime!&quot;;
      else
      {
          cout&lt;&lt;&quot;Not a prime number :( &quot;;
          cout&lt;&lt;&quot;Infact, &quot;&lt;&lt;num&lt;&lt;&quot; can be divided by: &quot;;
          for(int i=2; i&lt;num; i++) {
              if(num % i == 0)
              cout&lt;&lt;i&lt;&lt;&quot;, &quot;;
          }
          
          //What I want:&gt; cout&lt;&lt;&quot;Infact, &quot;&lt;&lt;num&lt;&lt;&quot; can be divided by: &quot;&lt;&lt;arrayOfDiiders;
      }
      return 0;
  }
  </code></pre>
  <p><strong>The below is quasi human language/c++ code, written to describe what I wanted to achieve.</strong></p>
  <pre><code>int allDividers(int num) {
  
  int arrayOfDiiders[]; //the array i wanted to make
  for(int i=2; i&lt;num; i++) {
      if(num % i == 0)
      // add i to the arrayOfDiiders[];
  }
  
  return arrayOfDiiders[];
  }
  </code></pre>
  <p>Other func that assertions if user input is prime number. Included incase relevant.</p>
  <pre><code>bool isPrime(int num){
      int countDivs = 0; 
      for(int i=1; i&lt;=num; i++) {
          if (num % i == 0) 
              countDivs++;
      }
      if (countDivs == 2) 
          return true;
      else 
          return false;
  } 
  </code></pre>
  <p>Thanks in advance.</p>