One Dimensional Array




An array that can be represented by only one dimension such as row or column and that holds finite number of same type of data items is called one dimensional (linear) array.
Here 1, 2, 3, … … …, 10 are index number, and
0, 10, 12, … … …, 39 are data items or elements of the array and B is the array name.
Symbolically an element of the array is expressed as Bi or B[i], which denotes ith element of the array, B.
Thus B[4], B[9] denotes respectively the 4th element and the 9th element of the array, B.
The name of the array usually is a name constituted by one or more characters.
Thus array name may be A, S, Stock, Array1 etc.
The element of an array may be number (integer or floating point number) or character



Expression of one dimensional array in C/C++:
For integer array:
int a[10];
For character array:
char b[30];
For floating point array:
float c[10];






Store an element into an array
B[4] = 19; it means 19 will be stored in the cell number 4 of the array of B
If there is any (previous) value that will be overwritten.

Read (retrieve) a value (element) from an array
x = B[6]; it means the value of x will be 20, since the cell number 6 of the array, B contains 20

Code in C/C++ for storing data in an array
int x[10];
for (i = 0; i < style="font-weight: bold;">Code in C/C++ for accessing data from an array and the data will be displayed on the monitor’s screen:
int AC[20];
for (i =0; i < style="font-weight: bold;">Here array name is AC and the size of the array is 20.

Preview <<





No comments:

Post a Comment

There was an error in this gadget

Followers

About Me

Dhaka, Dhaka, Bangladesh
..