What is Variables in C prgramming language , rules of variables in c language with type declaration
|
Posted On :
Sep-05-2011
| seen (509) times |
Article Word Count :
541
|
|
A variable is an entity whose value can change during program execution. A variable can be thought of as a symbolic representation of address of the memory space where values can be stored, accessed and changed. A specific location or address in the memory is allocated for each variable and the value of that variable is stored in that location.
|
A variable is an entity whose value can change during program execution. A variable can be thought of as a symbolic representation of address of the memory space where values can be stored, accessed and changed. A specific location or address in the memory is allocated for each variable and the value of that variable is stored in that location.
Each variable has a name, data-type, size, and the value it stores. All the variables must have their type indicated so that the compiler can record all the necessary information about them, generate the appropriate code during translation and allocating required space in memory.
Every programming language has its own set of rules that must be observed while
writing the names of variables. If the rules are not followed, the compiler reports
compilation error. Rules for Constructing Variable Name in C language are listed
below:
a. Variable name may be a combination of alphabets, digits or underscores.
Sometimes, an additional constraint on the number of characters in the
name is imposed by compilers in which case its length should not exceed
8 characters.
b. First character must be an alphabet or an underscore (_).
c. No commas or blank spaces are allowed in a variable name.
d. Among the special symbols, only underscore can be used in a variable name.
e.g.: emp_age, item_4, etc.
e. No word, having a reserved meaning in C can be used for variable name.
Note that C language is a case-sensitive language which differentiates between lower case and upper case. Thus, CAT is different from Cat, cAT, CaT. Although any word complying with the rules cited above can be used as the variable name, it is advised tha you create variable names that have some meaning. Thus, you may chose sum as the variable name for storing sum of numbers rather than choosing X.
Type Declaration
C language is strongly typed language, meaning that all the variables must be declared before their use. Declaration does two things:
It tells the compiler what the variable name is.
It specifies what type of data the variable will hold.
In C language, a variable declaration has the form:
,
Here is one of the valid data types (e.g. int, float, char, etc.). List-of-variables is a comma-separated list of identifiers representing the program variables.
e.g.-
a. int i, j, k; //creates integer variables i,j and K
b. char ch; //creates a character type variable ch
Once variable has been declared in the above manner, the compiler creates a space in the memory and attaches the given name to this space This variable can now be used in the program.
A value is stored in a variable using assignment operation. Assignment is of the form:
Variable-name = ; Obviously, before assignment, the variable must be declared. e.g.: int i, j;
j = 5; i = 0 ;
C also allows assignment of a value to a variable at the time of declaration. It takes the following form:
|
|
Article Source :
http://www.articleseen.com/Article_What is Variables in C prgramming language , rules of variables in c language with type declaration_79770.aspx
|
Author Resource :
learncprogrammgs offering c programming online,c programming for beginners,c tutorials,variable in c, c program code, ,for loop programs in c language ,c language basics.
|
Keywords :
c programming step by step, c programming tutorial, c tutorial, c language, for loop programs in c, c language notes, c language b,
Category :
Reference and Education
:
College
|
|
|