title: Loop through array of unknown size C++
body: <p>I am trying to traverse a <code>double</code> array of an unknown size. </p>
  
  <p>Why does the following not work? </p>
  
  <pre><code>for (unsigned int = 1; i &lt; sizeof(anArray)/sizeof(double); i++) {
      ...
  }
  </code></pre>
  
  <p>Everything compiles fine (<code>g++ -Wall -Werror -std=c++11 app.cpp -o app</code>), but the program simply does not even enter the loop. </p>
  
  <p>Full function: </p>
  
  <pre><code>struct stock_data {
     int sell_index;
     int buy_index;
     double profit;
  };
  
  stock_data max_profit(double price_array[]) {
     int sell_index = -1, buy_index = -1, 
        min = 0;
  
     double profit = 0.0;
  
     for(int i = 1; i &lt; size; i++) {
  
        if(price_array[i] - price_array[min] &gt; profit) {
           sell_index = min;
           buy_index = i;
           profit = price_array[i] - price_array[min];
        }
  
        if(price_array[i] &lt; price_array[min]) {
          min = i;
        }
     }  
  
     return {sell_index, buy_index, profit};
  }
  
  int main() {
     double yesterday[] = {0.1, 0.2, 0.3, 0.4};
     stock_data data = max_profit(yesterday);
     cout &lt;&lt; data.profit &lt;&lt; endl;
  }
  </code></pre>