May 15, 2021 Arduino
Before we begin to explain variable types, we need to identify a very important topic, called variable ranges.
The variable in the C language used by Arduino has a property called scope. s cope is an area of the program where three places can declare variables. They are:
The variable declared in a function or block of code is a local variable. /b10> They can only be used by statements in the function or block of code. /b11> Local variables cannot run outside of themselves. The following is an example of using a local variable:
Void setup () { } Void loop () { int x , y ; int z ; Local variable declaration x = 0; y = 0; actual initialization z = 10; }
Global variables are defined outside of all functions and are usually at the top of the program. /b10> Global variables maintain their value throughout the life of the program.
Global variables can be accessed by any function. /b10> That is, a global variable can be used after being declared throughout the program.
The following example uses global and local variables:
Int T , S ; float c = 0 ; Global variable declaration Void setup () { } Void loop () { int x , y ; int z ; Local variable declaration x = 0; y = 0; actual initialization z = 10; }