Variable

Variable:

Variable is a name of memory location where we can store any data. It can store only single data (Latest data) at a time. In C, a variable must be declared before it can be used. Variables can be declared at the start of any block of code, but most are found at the start of each function.

A declaration begins with the type, followed by the name of one or more variables. For example,

DataType  Name_of_Variable_Name;

int a,b,c;

 

Variable Names

Every variable has a name and a value. The name identifies the variable, the value stores data. There is a limitation on what these names can be. Every variable name in C must start with a letter; the rest of the name can consist of letters, numbers and underscore characters. C recognizes upper and lower case characters as being different. you cannot use any of C’s keywords like main, while, switch etc as variable names.

Ex. a , abc, sum , add1

Local Variables

Local variables are declared within the body of a function, and can only be used within that function only.

Syntax:

Void main( )

{

int a,b,c;

}

 

Void fun1()

{    int x,y,z;    }

Here a,b,c are the local variable of void main() function and it can’t be used within fun1() Function. And x, y and z are local variable of fun1().

Global Variable

A global variable declaration looks normal, but is located outside any of the program’s functions. This is usually done at the beginning of the program file, but after preprocessor directives. The variable is not declared again in the body of the functions which access it.

Syntax:

#include<stdio.h>

int a,b,c;

void main()

{

}

Void fun1()

{

}

Here a,b,c are global variable .and these variable cab be accessed (used) within a whole program.

 

error: Content is protected !!