- Arduino - Network Communication
- Arduino - Wireless Communication
- Arduino - Tone Library
- Arduino - Stepper Motor
- Arduino - Servo Motor
- Arduino - DC Motor
- Arduino - Connecting Switch
- Arduino - Ultrasonic Sensor
- Arduino - PIR Sensor
- Arduino - Water Detector / Sensor
- Arduino - Temperature Sensor
- Arduino - Humidity Sensor
- Arduino - Keyboard Serial
- Arduino - Mouse Button Control
- Arduino - Keyboard Message
- Arduino - Keyboard Logout
- Arduino - LED Bar Graph
- Arduino - Reading Analog Voltage
- Arduino - Fading LED
- Arduino - Blinking LED
- Arduino - Serial Peripheral Interface
- Arduino - Inter Integrated Circuit
- Arduino - Communication
- Arduino - Interrupts
- Arduino - Random Numbers
- Arduino - Pulse Width Modulation
- Arduino - Due & Zero
- Arduino - Trigonometric Functions
- Arduino - Math Library
- Arduino - Character Functions
- Arduino - Advanced I/O Function
- Arduino - I/O Functions
- Arduino - Arrays
- Arduino - Time
- Arduino - String Object
- Arduino - Strings
- Arduino - Functions
- Arduino - Loops
- Arduino - Control Statements
- Arduino - Operators
- Arduino - Variables & Constants
- Arduino - Data Types
- Arduino - Program Structure
- Arduino - Installation
- Arduino - Board Description
- Arduino - Overview
- Arduino - Home
Arduino Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Arduino - Variables & Constants
Before we start explaining the variable types, a very important subject we need to make sure, you fully understand is called the variable scope.
What is Variable Scope?
Variables in C programming language, which Arduino uses, have a property called scope. A scope is a region of the program and there are three places where variables can be declared. They are −
Inside a function or a block, which is called local variables.
In the definition of function parameters, which is called formal parameters.
Outside of all functions, which is called global variables.
Local Variables
Variables that are declared inside a function or block are local variables. They can be used only by the statements that are inside that function or block of code. Local variables are not known to function outside their own. Following is the example using local variables −
Void setup () { } Void loop () { int x , y ; int z ; Local variable declaration x = 0; y = 0; actual initiapzation z = 10; }
Global Variables
Global variables are defined outside of all the functions, usually at the top of the program. The global variables will hold their value throughout the pfe-time of your program.
A global variable can be accessed by any function. That is, a global variable is available for use throughout your entire program after its declaration.
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 initiapzation z = 10; }Advertisements