Plus Two Computer Application Notes Chapter 2 Arrays

Kerala State Board New Syllabus Plus Two Computer Application Notes Chapter 2 Arrays.

Kerala Plus Two Computer Application Notes Chapter 2 Arrays

An array is a collection of elements with same data type Or with the same name we can store many elements, the first or second or third etc can be distinguished by using the index(subscript). The first element’s index is 0, the second element’s index is 1, and so on.

Declaring arrays
Suppose we want to find the sum of 100 numbers then we have to declare 100 variables to store the values. It is laborious work. Hence the need for an array arises.

Syntax: data_type array_name[size];

To store 100 numbers the array declaration is as follows
int n[100]; By this, we store 100 numbers. The index of the first element is 0 and the index of last element is 99.

Memory allocation for arrays
The amount of memory requirement is directly related to its type and size.
int n[100]; It requires 2 Bytes (for each integer)*100 = 200 Bytes.
float d[100]; It requires 4 Bytes(for each float)*100 = 400 Bytes.

Array initialization
Array can be initialized in the time of declaration.
Eg. int age[4] = {16, 17, 15, 18};

Accessing elements of arrays
Normally loops are used to store and access elements in an array.
Eg.

int mark[50], i;
for(i=0; i<50; i++)
{
cout<<“Enter value formark”<<i+1; cin>>mark[i];
}
cout<<“The marks are given below:’’;
for(i=0; i<50; i++)
cout<<mark[i];

Leave a Comment