Variables

A variable is a way of naming and storing a numerical value for later use by the program. a variable needs to be declared and optionally assigned to the value needing to be stored.

A scope is a region of the program and there are three places where variables can be declared. They are:

  1. Inside a function or a block, which is called local variables.
  2. In the definition of function parameters, which is called formal parameters.
  3. Outside of all functions, which is called global 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.

Void setup ()
{
}
Void loop ()
{
int x , y ;
int z ; Local variable declaration
x= 0;
y=0; actual initialization
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 life-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.

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

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: