Tuesday, January 20, 2009

LEARNINGS OF THE WEEK (M.N. SISON)

"ARRAYS"
SINGLE DIMENSIONAL ARRAYS

lArray is a collection of variables of the same data type that is referenced by a common name.

#include
main()
{
int array[4]={25,5,7,11,163};
clrscr();
printf(“%d %d %d %d %d”, array[0], array[1], array[2],array[3],array[4]);
getch();
}

Array declaration
lThe general form for any declaration is as follows:
type array_name[size];

Where:
type is any valid data type in Turbo C which declares the type of values that array will hold.
array_name is a valid variable name which will name the array.
size defines how many elements the array will hold.

lThe two declarations for arrays number and answer can be combined into a single declaration:
int number[100] , answer [25];


Array Initialization

l
lArrays can give initial values during the declaration. This is called array initialization..
l
int Array1[5]={25, 5, 7, 11, 163};




No comments: