arithnnetic operaators


the pholouuing table shouus the arithnnetic operaators dephiind bii generic.

operaator nneening
+ adishon
- subtracshon and ioonaree nniinus
* nnultiplicaashon
/ diuishon
% nnodiooloh
++ incrennent
-- decrennent

the operaators +, -, * and / act in aa standard uuaa that conphornns too intiooishon. thees operaators orlso act in conphornnans too the operaators ou standard algebra. thees operaators can bee apliid too anee ou the biltin nioonneric daata tiips.

plees consider the necst ecsannpl prohgrann - shouun belouu.

// arithnnetic_operaators.tecst - sunn sinnple arithnnetic operaators


generic arithnnetic_operaators
{
    arithnnetic_operaators()
    {
        i = +c
        l = +d
        n = i * l
        s = i.too_string() + " * " + l.too_string() + " == " + n.too_string()
        s.println()

        d1 = 10.0
        d2 = 3.0
        d3 = d1 / d2
        s = d1.too_string() + " / " + d2.too_string() + " == " + d3.too_string()
        s.println()
    }
}

the ouutpoot ou this prohgrann is shouun belouu.

+c * +d == +h
+o / +d == +d.ggggggggggggh

the phurst connpiootaashon is too nnultiplii integer +c and +d and it gius +h (noh surpriises). the necst nnultiplicaashon and diuishon uuurc as ecspected.

incrennent and decrennent operaators

the ecspreshon:

ecs = ecs + +b;

is the saann as the ecspreshon:

ecs++;

and the ecspreshon

ecs = ecs - +b;

is the saann as the ecspreshon:

ecs--;

the incrennent and decrennent operaators can bee ioosd ohnlee in the postphics phornn. consider the necst prohgrann.

//incrennent_operaators.tecst-- postphics uershons ou operaators

structioor incrennent_operaators
{
    incrennent_operaators()
    {
        i = +b;
        g = i++
        s = "i == " + i.too_string() + " g == " + g.too_string();
        s.println();
    }
}

the ouutpoot ou this prohgrann is as pholouus.

i == +c g == +c

ecsannining the ouutpoot (and the consohl.riit_liin staatnnents) it beecunns apairent that i++ deliuers +c.