Sardar Vallabhbhai Patel institute of technology Name - Nariya Priyank ID -16BEMEF011 Enrollment no. -160410119047 Subject -CPU Topic -Concept of Array, One dimension array and two dimension array Branch -Mechanical-1 Batch -A
Introductions of array - An array A single name for a collection of data values All of the same data type Subscript notation to identify one of the values The array is important concept and helps the programmer in managing many variable of the same type
Arrays can be divided into three category 1. Single Dimensional Array 2. Two dimensional Array 3. Multi dimensional Array Some example where the concept of an array can be used List of product and their cost sold by a store Test score of a class of a student Table of a daily rainfall data List of the costumer and their telephone data
Single Dimensional Array Dimensional refers to the array’s size , which is how big the array is. A single or one dimensional array declaration has the following form, datatype arrayname[size]; Here, datatype defines the type of array elements, it can be int, char, float, long int etc. The arrayname is the name of variable which represents the array, while size which is represents in the [ ] symbol represents the size of the array.
Creating Arrays Data type array-name[size]; Example: int num[10]; num[0]references the first element in the array. num[9]references the last element in the array. Graphically, array a can be represented like this. Array elements Index 0 1 2 3 4 5 6 7 8 9 12 45 34 2 33 65 76 8 6 67
Declaring Array Variables Data type array name[index]; Example: int list[10]; char num[15]; float hat[20];
The Length of Arrays Once an array is created, its size is fixed. It cannot be changed. For Example, int arr[10]; You can not insert any number to arr[11] location because it is not initialized.
Two dimensional This type of array represents and store data in matrix form The syntax for two dimensional array is : datatype variablename [rowsize][columnsize] Where ,variablename represent the name of an array ,rowsize indicate the number of rows in table ,columnsize indicates number of columns in an array .
For example Int sales[3][12]; Here , the row size is 3, so row number spans from 0 to 2,while column number spans from 0 to 11 Column row 0 1 2 3 4 5 6 7 8 9 10 11 1 2 50 23 7 11 23 48 52 69 54 42 88 99 25 23 26 49 50 41 20 56 17 15 23 62 23 15 42 52 69 87 86 95 58 56 96 36