array out of range for dynamic array

 

What's wrong with following code?

//+------------------------------------------------------------------+
//|                                                          bbb.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   double  aaa[];
   aaa[1]=0;
  }
//+------------------------------------------------------------------+


2014.02.11 20:02:06.102    bbb (EURUSD,M1)    array out of range in 'bbb.mq5' (16,7)

 
kwang1:

What's wrong with following code?


2014.02.11 20:02:06.102    bbb (EURUSD,M1)    array out of range in 'bbb.mq5' (16,7)

You have to specify the size of your dynamic array. You can do this by using the ArrayResize() funtion.

   double  aaa[];
   ArrayResize(aaa,2);
   aaa[0]=10;
   aaa[1]=20;
   Print("aaa[1] = "+DoubleToString(aaa[1]));
 
Malacarne:

You have to specify the size of your dynamic array. You can do this by using the ArrayResize() funtion.

thanks a lot.........
Reason: