Variable in C Language
Variables is a reminiscence areas.This location is used to retailer the worth of the variable.
Its worth will be modified.we will change worth of a variable throughout execution of a program.
There are some guidelines for defing variables
- Variables are case delicate
- A variable can have Alphabets, underscore(_) and digit.
- No particular symbols are allowed aside from underscore.
- A variable title can begin with alphabet and underscore solely. It could possibly’t begin with digit.
- Clean areas can’t be utilized in variable names.
- A variable title should not be any reserved phrase or key phrase e.g. int, float and so forth.
1 |
Ex:- int age; float wage; int _num; int num76p; |
Variable declaration
data_type variable_name; Ex:-
int a, b, c; char title, ch;
Variable initialization
data_type variable_name = worth; Ex:-
int a = 60, b = 90; char title = �alok�, ch=�l�;
TYPES OF VARIABLE
- native variable
- static variable
- world variable
- exterior variable
- automated variable
Native Variable
native variables shall be contained in the perform solely.
a neighborhood variable is a variable that’s given native scope.
It could possibly�t be accessed outdoors the perform.
1 |
int primary(){ int a = 20, b = 25;// a, b are native variables of primary perform |
Static Variable
a static variable is a variable that has been allotted statically in order that its lifetime or “extent” extends throughout your entire run of this system.
Static variable that’s declared with static
key phrase.
1 |
void func() {static int x = 0; /* x is initialized solely as soon as throughout 5 calls of func() and the variable will get incremented 5 instances after these calls. The ultimate worth of x shall be 5. */x++;printf("%dn", x); // outputs the worth of x}int primary() { //int argc, char *argv[] inside the primary is non-compulsory within the explicit programfunc(); // prints 1func(); // prints 2func(); // prints 3func(); // prints 4func(); // prints 5return 0;} |
World Variable
A worldwide variable is a variable with world scope.
This variable is outlined outdoors the primary perform.
These variables will be accessed from anyplace in this system.
This variable is seen to primary perform and all different sub capabilities.
1 |
int m = 22, n = 44;//World variable void primary(){ |