[A89] Re: random numbers, pointers, problems


[A89] Re: random numbers, pointers, problems

> Excuse the stupid question: So you don't have to initialize normal
> variables?

Normal variables do not have to be initialized. At run time, some memory is
allocated for them, and if you initialized them, that value is copied to the
memory. Otherwise, they contain the previous value left there from whenever
that memory was last used, by any program.

Static variables use memory that is inside the program. They are initialized
at compile time. When you compile the program, the initialized value is
copied. During run time, this value can be changed. When the program is run
again, the last value is there. So if you create a static variable X, and
initialize it to 5, it is then set to 5 when the program is compiled. If
during the first run, you change X to be 3, and leave it that way, it will
continue to be 3. The next time you run the program, X would still then be
3. Note this is different for archived programs, since a copy of the
archived program is used, and the changes made to the programs memory are
not saved.

B Clark

Follow-Ups: References: