Variable in C Language
Variables is a reminiscence areas.This location is used to retailer the worth of the variable.
Its worth may be modified.we are able to 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 actually’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 on.
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
- international 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 actually�t be accessed exterior the perform.
1 |
int essential(){ int a = 20, b = 25;// a, b are native variables of essential perform |
Static Variable
a static variable is a variable that has been allotted statically in order that its lifetime or “extent” extends throughout your complete 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 essential() { //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;} |
International Variable
A worldwide variable is a variable with international scope.
This variable is outlined exterior the primary perform.
These variables may be accessed from anyplace in this system.
This variable is seen to essential perform and all different sub features.
1 |
int m = 22, n = 44;//International variable void essential(){ |