Operators in C and C++: Difference between revisions

Content deleted Content added
Arithmetic operators: less clever; easier to read
Line 28:
|-
| {{rh}} colspan="2" | [[Addition]]
| stylealign="text-align:center;" | {{nowrap| 1=<code>a '''+''' b</code>}}
| {{cpp|1=R K::operator +(S b);}}
| {{cpp|1=R operator +(K a, S b);}}
|-
| {{rh}} colspan="2" | [[Subtraction]]
| stylealign="text-align:center;" | <code>a '''-''' b</code>
| {{cpp|1=R K::operator -(S b);}}
| {{cpp|1=R operator -(K a, S b);}}
|-
| {{rh}} colspan="2" | [[Unary operation|Unary]] plus; [[Type conversion#Type promotion|integer promotion]]
| stylealign="text-align:center;" | <code>'''+'''a</code>
| {{cpp|1=R K::operator +();}}
| {{cpp|1=R operator +(K a);}}
|-
| {{rh}} colspan="2" | [[Unary operation|Unary]] minus; [[additive inverse]]
| stylealign="text-align:center;" | <code>'''-'''a</code>
| {{cpp|1=R K::operator -();}}
| {{cpp|1=R operator -(K a);}}
|-
| {{rh}} colspan="2" | [[Multiplication]]
| stylealign="text-align:center;" | <code>a '''*''' b</code>
| {{cpp|1=R K::operator *(S b);}}
| {{cpp|1=R operator *(K a, S b);}}
|-
| {{rh}} colspan="2" | [[Division (mathematics)|Division]]
| stylealign="text-align:center;" | <code>a '''/''' b</code>
| {{cpp|1=R K::operator /(S b);}}
| {{cpp|1=R operator /(K a, S b);}}
|-
| {{rh}} colspan="2" | [[Modulo operation|Modulo]]<ref name="modulo" group="lower-alpha" />
| stylealign="text-align:center;" | <code>a '''%''' b</code>
| {{cpp|1=R K::operator %(S b);}}
| {{cpp|1=R operator %(K a, S b);}}
|-
| width="15%" {{rh}} rowspancolspan="32" | Prefix [[Increment and decrement operators|Incrementincrement]]
| width="11%" align="center" | <code>'''++'''a</code>
| width="8%" {{rh}} | Prefix
| width="25%" | {{cpp|1=R& K::operator ++(K& a);}}
| width="11%" align="center" | <code>'''++'''a</code>
| width="25%" | {{cpp|1=R& K::operator ++(K& a);}}
| width="25%" | {{cpp|1=R& operator ++(K& a);}}
|-
| {{rh}} rowspancolspan="2" | Postfix increment
| rowspanalign="2" style="text-align:center;" | <code>a'''++'''</code>
| {{cpp|1=R K::operator ++(int);}} {{efn|name=dummy-int|The {{cpp|int}} is a dummy parameter to differentiate between prefix and postfix.}}
| {{cpp|1=R operator ++(K& a, int);}} {{efn|name=dummy-int}}
|-
| {{rh}} colspan="2" style="font-size:smaller;" | REMOVePrefix [[Increment and decrement operators|decrement]]
| stylealign="text-align:center;" | <code>'''--'''a</code>
|-
| {{rh}} rowspan="3" | [[Increment and decrement operators|Decrement]]
| {{rh}} | Prefix
| style="text-align:center;" | <code>'''--'''a</code>
| {{cpp|1=R& K::operator --();}}
| {{cpp|1=R& operator --(K& a);}}
|-
| {{rh}} rowspancolspan="2" | Postfix decrement
| rowspanalign="2" style="text-align:center;" | <code>a'''--'''</code>
| {{cpp|1=R K::operator --(int);}} {{efn|name=dummy-int}}
| {{cpp|1=R operator --(K& a, int);}} {{efn|name=dummy-int}}
|-
| {{rh}} colspan="2" style="font-size:smaller;" | REMVOE
|}