Framework (A-Z)

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Name

static

Examples
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  // x is initialized only once across the calls of loop()
  static int x = 0;   
  Serial.println(x);  // outputs the value of x
  x = x + 1;  
  delay(200);
}
Description the static qualifier is used to create a static variable, its lifetime extends across the entire run of the program. As shown in the example the static variable x is only visible inside loop(). Try to remove the static qualifier in the axample above and see the difference when printing the output.
Syntax
static datatype variablename
Parameters
datatype any data type: int, double, long, char, byte, etc
variablename a valid variable name
Usage Application
Updated on July 07, 2011 11:09:02pm PDT

Creative Commons License