next up previous contents
Next: 5.3.2 Persistent Global Variables Up: 5.3 Local and Global Previous: 5.3 Local and Global

5.3.1 Variable Initialization

Local and global variables can be initialized when they are declared. If no initialization value is given, the variable is initialized to zero.

    int foo()
      int x;        /* create local variable x
                       with initial value 0    */
      int y= 7;     /* create local variable y
                       with initial value 7    */

    float z=3.0;    /* create global variable z
                       with initial value 3.0  */

Local variables are initialized whenever the function containing them runs.

Global variables are initialized whenever a reset condition occurs. Reset conditions occur when:

  1. New code is downloaded;
  2. The main() procedure is run;
  3. System hardware reset occurs.

Fred G. Martin
Fri Mar 29 17:44:15 EST 1996