MQL4 - automated forex trading   /  

Documentation

ODL Securities

MQL4 Reference  Basics  Variables  Static variables

 

The memory class of "static" defines a static variable. The specifier "static" is declared before a data type.

Example:

int somefunc()
  {
   static int flag=10;
   ....
   return(flag);
  }

Static variables are stored in the permanent memory, their values do not get lost when the function is exited. Any variables in a block, except for formal parameters of the function, can be defined as static. The static variable can be initialized by a constant of the corresponded type, unlike a simple local variable which can be initialized by any expression. If there is no explicit initialization, the static variable is initialized with zero. Static variables are initialized only once before calling of the "init()" function, that is at exit from the function inside which the static variable is declared, the value of this variable not getting lost.