Variable declaration in c

Variable declaration

A name of the memory location is called variable

Before using any variable in the program, it must be declared first.

Declaration of variable means , needs to mention data type and name of identifier.

In c program language, variable declarations must be existed on top of the programs after opening the curly brace( { )before writing the first statement.

In variable declaration, name ofthevariable must start with alphabet or under scoreonly.

In variable declaration in c , maximum length of a variable name is 3 characters, after 3 characters, compiler will not consider the remaining characters .

In variable declaration , existing key words ,operators , separators and constant values are not allowed.

In variable declaration, at least single space should be required between data type andvariable name.

When we are declaring multiple variables of same data type , then it isrequired to go for comma (,) as a separator.

Syntax :-

Data type variable ;


Inta ; /*incorrect*/

Int a/*incorrect*/

Int a ; /*correct*/

Int a, b, c, d; /*correct*/

Int abc , c, d; /*correct*/

Int 1a,1b,1c;  /*incorrect*/

Int a1, b1, c1; /*correct*/

Int if ; /*incorrect*/

Int IF;/*incorrect*/

Int _if ;/*correct*/

Int total-sal ;/*incorrect*/

Int total_sal; /*correct*/

Int _1, _2,_3;/*correct*/

Value int i ; float f ; (decimal part contains 6 digits when displaying  the output so

              Value          int i;             float f;
5/2       2      2.5
5.0/2        2      2.5
5/2.0       2      2.5
5.0/2.0       2      2.5
2/5       0     0.0
2.0/5       0      0.4

Operator behavior is always operand dependent only , i.e. Depending on the input value. The behavior  of the operator will be changed.

The return value behavior is always variable dependent only, i.e. depending on the data type,the return value will be converted automatically to corresponding data type.

In implantation, whenever an operator returns an integer value and we need to assign it to float variable, then data will be converted into float format automatically by adding “ .0” .

In implementation, whenever an operator returns float data andwe need to assign it to integer variable, than only decimal part will be converted into corresponding type.

By default, whenever we are declaring a variable, it holds garbage value only.