Variables-: A variable is data name that may be used to store a data valueonly constant that remain unchanged during the execution of a program a variable may take different values at different times during execution.We used several variable in our program . variable store the value of money at the end of each year A variable name can be chosen by the programmer in a meaningful way so as to replace function or nature in the program some example of some names are here height, Total, weight, amount etc.
In other words we can say that the variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines the size and layout of the variable’s memory. the range of values that can be stored within that memory and the set of operations that can be applied to the variable.
Rules of variable declaration-:
Variable name may consist of letter, digits and the underscore character(_) subject to the following conditions
1 they must begin with a letter some system permit underscore as the first character .
2.ANSI standard recognizes a length of 31 characters however length should not be normally more than 8 characters since only the first 8 characters are treated as significant by many compilers
3. uppercase and lowercase are significant that is the variable total is not the same as total equity TOTAL .
4. it should not be a keyword.
5 white space is not allowed some
Valid variable are here example are here Ram, Shyam, Mohan, Sohan Delhi Rajasthan
Types of variable name -: Like any other programming language C support four type variable name. These are the
- Int -: All the number of variable are declare in this integer value. The integer value are the 0 to 9. In this variable types all number are permitted.
- char -: It means all the character value are store in this variable type.as like if we write a name we can define in this type variable.
- float -: in this type variable store the single-precision floating point value.
- void-: in this type variable Represents the absence of type.
- double-: This type variable -precision floating point value.
How to declare a variable in c programming language
There are some rules for declare a variable in c programming language. Follow these rules
A variable declaration is very useful when we are using multiple files . We can define our variable in one of the files which will be available at the time of linking of the program. we shall use the keyword netnic to declare a variable at any place. we can declare a variable multiple times in our C program, it can be defined only once in a file, a function, or a block of code..For syntax of variable declare
For example if we are giving the integer value then we declare the variable name
Int x; // x is the integer variable name
int y; // y is the integer variable name
int netnic; // netnic is the integer variable name
int vikram; //vikram is the integer variable name
int ramla; // ramla is the integer variable name
character variable name and declare type.
char a; //a is the character value
char b; //b is the character value
char roshan; //roshan is the character value
Like we declare float and double
float c ;
A complete example of declare a variable-:
// variable declaration in c programming
int b; // we can write here as like int a,b,c;
/* variable definition */ for commenting
/* actual initialization */ for commenting line
c=a+b; // for adding two variable number
printf(" The total number of c :%d \n",c);
printf(" The value of f : %F \n",f);
Output of this program -:
The total number of c :60
The value of f : 46.33
Read More about data type in c language