Author: Stan Eisenstat
Subject: Re: [Cs223] Static Variables
Date: Friday, 07 Feb 2020, 16:05:35
> Message Posted By: Unknown > > Hi > > Do static variables need to be initialized on the same line as they are > declared or can we do something like this: > > static int index; > index = 0; Remember that a static local variable is initialized (either to the value specified in the declaration or to the default of 0) at link time, which means that it is given its initial value when the program is loaded into memory and begins execution. If the function includes an additional assignment to the variable, as above, that statement is executed EVERY time that the function is called, which defeats the purpose of persistent storage. --Stan-PREV INDEX NEXT