title: Removing cout statement causing segmentation fault
body: <p>This is a function in my program. With the cout statement there the program compiles and runs. If I remove the cout statement I get a segmentation fault returned. I'm using G++ compiler on linux mint. Anyone have any thoughts on this?</p>
  
  <pre><code>int findFactors(int n,int factors[],int numFactors)
  {
    int m=n;
    int k=2;
    int i;
  
   while(m!=1)
   {
    for(k=2;k&lt;=m;k++)
    {
     if(m%k==0)
      {
        factors[i]=k;
        cout&lt;&lt;"Prime Factor: "&lt;&lt;factors[i]&lt;&lt;endl;//This is the offending statement!
        factors[i++];
        numFactors++;
        break;
      }
    }
     m=(m/k);
   }
  
    return numFactors;
  }   
  </code></pre>