"Array out of range" error on zero index

 

Hello traders

Look at this part of simple code. I receive "Array out of range" error when running this code. Everything seems correct. Why?

//+------------------------------------------------------------------+
//|                                           fast-start-example.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

string            symbol;
ENUM_TIMEFRAMES   timeframe;


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
  
   symbol=Symbol();
   timeframe="D1";
   
   double tmp[];

   tmp[0] = 1111;
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

  }
//+------------------------------------------------------------------+


 
Your dynamic array is of size 0

You need to do a ArrayResize before you can use it.
 
Dominik Egert:
Your dynamic array is of size 0

You need to do a ArrayResize before you can use it.

Thnaks


Anytime I wanna set a value in my array do I need to call ArrayResize ? Or just once is enough?

 
Soroush:

Thnaks


Anytime I wanna set a value in my array do I need to call ArrayResize ? Or just once is enough?

You need to read carefully the Array documentation... Clearly you don't know how Arrays work in MQL5...
 
Flavio Jarabeck:
You need to read carefully the Array documentation... Clearly you don't know how Arrays work in MQL5...
Now I know. I should allocate memory to an array before using it. Thanks.
Reason: