/*Static Variables:
Definition: A static variable retains its value between function calls.
Scope: Its scope is local to the function/block where it is defined, but it remains in existence during the entire runtime of the program.
Usage: Static variables are used when you want a variable to maintain its value even after exiting the scope in which it was created.
Declaration (in C/C++): It's declared by placing the keyword static before the variable's type */
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 bps
}
void loop() {
incrementCounter(); // Call the function to increment and display the counter
delay(1000); // Wait for 1 second before the next loop iteration
}
void incrementCounter() {
// int counter = 0; // local Automatic Variable
static int counter = 0; // Declare a static variable
counter++; // counter= counter + 1; Increment the counter
Serial.println(counter); // Print the current value of the counter
}