Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Arduino variables and constants


May 15, 2021 Arduino


Table of contents


Before we begin to explain variable types, we need to identify a very important topic, called variable ranges.

What is a variable range?

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:

  • Inside a function or block of code, it is called a local variable.
  • In the definition of a function argument, it is called a formal argument.
  • Outside of all functions, it is called a global variable.

The local variable

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 variable

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;
}