Download MetaTrader 5

Multidimensional array size depending on a parameter: how to get this?

To add comments, please log in or register
Publish your article and thousands of people all over the world will read it!
hardhu
90
hardhu 2013.12.12 19:39 

Hello everybdy,

according to documentation (https://www.mql5.com/en/articles/567), when declaring an array, its size can be specified directly as a number  or using a predefined constant: 

 

#define SIZE 3

double Variable[SIZE];

 

Unfortunately this seems not to work with multidimensional array, that is:

 

#define SIZE 3

double Variable[4][SIZE]

 

leads to an error in the compilation. Is there any way to define multidimensional array whose size of dimensions others than the first one depends on some parameter constant, so that this size, if several arrays of this type are used in the code, can be changed once for all simply modifying that parameter? 

MQL5 Programming Basics: Arrays
MQL5 Programming Basics: Arrays
  • 2013.03.11
  • Dmitry Fedoseev
  • www.mql5.com
Introduction Arrays are an integral part of almost any programming language along with variables and functions. Many novice programmers are often afraid of arrays. It sounds strange but it is true! I can assure you that they are not scary at all. In fact, arrays are similar to regular variables. Without going into detail about the notation...
Alain Verleyen
Moderator
30742
Alain Verleyen 2013.12.12 19:47  
#define SIZE 3

double Variable[4][SIZE];
hardhu
90
hardhu 2013.12.12 20:15  
angevoyageur:

Thank you for your answer, the error was in fact related to a semicolon, but not that one 

 

#define SIZE 3

double Variable[4][SIZE];

 

That was a missing semicolon due to an error in copying and pasting the code.

The original error was instead:

 

#define SIZE 3;

 where I put an extra semicolon in the define directive....sorry, too much in front of the monitor today :-(

To add comments, please log in or register