Download MetaTrader 5

What is the difference between NULL and "" ?

To add comments, please log in or register
macpee
487
macpee  
Can someone tell the difference between
NULL
and
""
Thank you in advance.
Keith Watford
Moderator
10651
Keith Watford  

NULL is basically no value as far as I understand when a string variable is assigned.

Note


string a=NULL;
Print(a=="");

‌Will not return true

whereas


string a=NULL;
Print(a==NULL);

‌and


string a="";
Print(a=="");

‌will both return true

Ex Ovo Omnia
3348
Ex Ovo Omnia  
I would recommend to avoid NULL in MQL completely unless you have tested behaviour for the particular datatype. It is implemented inconsistently, for string it means an uninitialised string, while for integer it means either an uninitialised integer or zero, for object pointers it means uninitialised or void objects however not the destroyed pointers.
whroeder1
15917
whroeder1  

I agree, (except for pointers where you specifically check for NULL,) don't use it.

You can only use NULL in calls where the documentation specifically mentions it, and those are mostly a substitution for _Symbol.‌

To add comments, please log in or register