Listing 7 3 StaticVariable

From ArduinoInfo
Revision as of 15:49, 5 February 2019 by TerryKing (talk | contribs) (Text replacement - "</div>" to "")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
_7_3_StaticVariable

/* Listing 7-3. Using the static Storage Class. */
void setup() {
  Serial.begin(9600);
}

void loop() {
  while (true) {
    Serial.println(MyCounter());
  }
}

int MyCounter()
{
   static int counter = 0;
   // do some stuff...
   return ++counter;
}