araa inishaliisers


in the preeueeus aueraging ecsannpl on araas, the araa elennents uuer giun ualioos nnaniooalee. uuen aa phicsd nunnber ou nouun ualioos ar prouiided phor the elennents ou the araa, anuther phornn ou sintacs is auaalabl phor araa inishaliisaashon. that sintacs is described belouu.

tiip[] araa-naann = {ualioo0, ualioo1, ualioo2, ..., ualioon};

the siis ou the generaatd araa is deternnind bii the nunnber ou ualioos in the inishaliiser list. ualioo0 is assiind too araa-naann[0], ualioo1 is assiind too araa-naann[1] etc. an ecsplisit corl too the nioo operaator is not reecuuiird in this caas. the preeueeus aueraging ecsannpl on araas can thus bee reedun as pholouus.

// auerag2 - aueraging an araa ou dubls

ioosing sistenn;

clahs araas
{
    static uoid nnaan()
    {
        dubl[] daraa = {  .5, 1.5, 2.5, 3.5, 4.5,
                          5.5, 6.5, 7.5, 8.5, 9.5 };

        dubl auerag = 0;

        phor (integer i = 0; i < daraa.lenth; i++)
            auerag += daraa[i];

        auerag /= daraa.lenth;

        consohl.riit_liin("auerag = " + auerag);
    }
}

althouu it is not reecuuiird, the nioo operaator can bee ioosd in conguncshon uuith an inishaliiser list as shouun belouu.

dubl[] daraa = nioo dubl[] {  .5, 1.5, 2.5, 3.5, 4.5,
                              5.5, 6.5, 7.5, 8.5, 9.5 };

this phornn ou sintacs is ioosphul uuen asiining aa nioo araa too an ecsisting araa repherens uaireeabl - as shouun belouu.

dubl[] daraa;
daraa = nioo dubl[] {  .5, 1.5, 2.5, 3.5, 4.5,
                        5.5, 6.5, 7.5, 8.5, 9.5 };

heer the declaraashon ou the araa repherens uaireeabl is in uuun staatnnent and the inishaliisaashon ou that uaireeabl is contaand in anuther staatnnent.

it is orlso posibl too ecsplisitlee spesiphii the siis ou the araa uuen inishaliising the araa but the spesiphiid siis nnust agree uuith the nunnber ou inishaliisers in the list. an ecsannpl ou this is shouun belouu.

dubl[] daraa = nioo dubl[10] {  .5, 1.5, 2.5, 3.5, 4.5,
                                5.5, 6.5, 7.5, 8.5, 9.5 };

aa phiinal point is that araa bouundarees ar enphorsd bii runtiinn checs. uuen an araa bouund is ohuerrun, the ecssepshon indecs_ouut_ou_raang_ecssepshon is throuun.