[Main]
Title=Global variables retain value?
See Also=28: How do I store variables so they retain their values

[Top]
<TABLE CELLPADDING="4"><TR><TD VALIGN="TOP"><B>Q:</B></TD><TD>
If I understand correctly, if I have the following global variable in my program
<PRE>int a = 10;
</PRE>
and if I change its value somewhere in the program to 20 (for example), its initial
value will be 20 (not 10) when I run the program next time???
</TD></TR><TR><TD VALIGN="TOP"><B>A:</B></TD><TD>
Exactly! Note that this is true only for global and static variables.
To force reinitializing, you must put explicitely something
like
<PRE>a = 10;
</PRE>
at the begining of the main program!
<BR><BR>
Note, however, that if the program is archived,
the initial values will be restored each time you run the program, because archived
programs are reloaded from the archive memory to the RAM on each start, similarly
to the programs are reloaded from disks on "standard" computers (PC, etc.) each
time when you start them. The same is true for compressed programs (for obvious
reasons) and if you use a data variable and have TIGCC create a copy every time
it is used.
</TD></TR></TABLE>
