Variables in the C++ programming language, which Arduino uses, have a property called scope. This is in contrast to early versions of languages such as BASIC where every variable is a global variable.
A global variable is one that can be seen by every function in a program. Local variables are only visible to the function in which they are declared. In the Arduino environment, any variable declared outside of a function (e.g. setup(), loop(), etc. ), is a global variable.
When programs start to get larger and more complex, local variables are a useful way to insure that only one function has access to its own variables. This prevents programming errors when one function inadvertently modifies variables used by another function.
※ ARDUINO BUY RECOMMENDATION
|Arduino UNO R3 Buy on Amazon|
|Official Arduino Starter Kit Buy on Amazon|
|ELEGOO UNO R3 Starter Kit Buy on Amazon|