Programming Arrays

Array

            a data str type in which all the elements must be of same type…

                                                OR

            it's the collection of finite no of homogenous data element which are stored n conconsective mem loations……..

one dimensional array : array —->singel row or column

two dimensional array : aray —–>rows & columns (table)..

1. arrary name uses same rules as identifier…

2. subscript is used to refer to an iindividual element wth in array…

3. subscript can be a non negative int const , a variable & an arithmatic expression….e,g X[10], NUM[N],           

    counter [c+1],  avg[subs],  Z[x*x]……..

Arrray Declearation

            type array _name [size];

            int     Z  [10];

elements of an array r always counted from zero…..

Array Initialization

            int NUM[6] = {8,4,9,5,1,7};

            int HU[100] = {0}; // all elements of hu'll store zero…

          float S NUM[ ] = {5.5, 2.4, 5.0, 6.9};

          float U NUM[4] = {5.5, 2.4, 5.0, 6.9, 8.8}; // wrong

Multidimensional Array

            we could do go up to 12 dimensions n C++ .all multidimensional array r internally as one    dimensionla

            e,g   int a [4] [5] [3]——>3dimensional

                    int b[4] [5] [2] [1]—> 4dimensional           

Passing Array To Function

            array can be used as an argument to a func…..

            array pass by value—->e,g basic data type

            arry pass by referrence—>e,g array by default

String Variable

Integer Array

            int a [10];

            cout <<a; // it'll print only the address of 1st byte…

Character Array                 

            char B[4] = {'t', 'r', 'u', 'e'};

            cout <<B;  // it'll print tru cuz in last byte it'll store null element , to print all true we [5]

String Array

            this type of char array s known as string array….

            char  name[25] = "sebastian 410";

            cout<< name;    //it'll print complete name…..

            but if

            char name [25];

            cin >> name ; // now if we in sebastian 410 it'll only print sebastian not 410 cuz it'll take space as   null element…for complete name we can use _ or cin.get(name, 25)

            char b [5] = {'t' ,'r','u','e'};

            cin>>b ;

            cout<<b;  // if we entered false it'll print complete false in this case there'll be no null & the next var           can be damaged so we'll use setw funtion to stop it e,g cin>>setw(5)>>b;

           

Two Dimensional Character Array

            char day [7] [10];

Array As Class Member Data