A variable is an identifier that is used to represent some specified type of information within a designated portion of the program.In the simplest form, a variable is an identifier that is used to represent a single data item i.e a numerical quantity or a character constant.
A C program contains the following lines.
int a,b,c;
char d;
..........
a=3;
b=5;
c=a+b;
d='a';
.........
a=4;
b=2;
c=a-b;
d='w';
The first two lines are type declarations,which state that a,b, and c are integer variables,and d is a character type variable.
The next four lines cause the following things to happen: the integer quantity 3 is assigned to a,5 is assigned to b,and the quantity represented by the sum a+b (i.e 8) is assigned to c.The character 'a' is assigned to d.
The last four lines redefine the values assigned to the variables .
Array is another kind of variable that is used extensively in C.An array is an identifier that refers to a collection of data items that all have the same name.The data items must all be of the same type (e.g all integers,all characters,etc.).The individual data items are represented by their corresponding array elements.
Suppose letter[9] is a 10-element array.The first element is referred to as letter[0],the second element as letter[1] and so on.
Saturday, December 5, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment