# Difference between revisions of "Arithmetic Operators"

m (→Syntax: format changed so that all entries occur in one box) |
(→Addition: Addition of two pointers does not exist.) |
||

Line 56: | Line 56: | ||

=== Addition === | === Addition === | ||

− | x = 10 + 7; | + | x = 10 + 7; // On integer |

− | y = 1.23 + 3.45; | + | y = 1.23 + 3.45; // On float |

− | + | p = p + 1; // One pointer and one integer used as a byte offset | |

− | |||

− | |||

=== Subtraction === | === Subtraction === | ||

x = 10 - 7; | x = 10 - 7; |

## Revision as of 10:13, 20 December 2011

Work in Progress

## Contents

## Operator Names

+ | Addition | x + y | x add y | -or- | x plus y | |

- | Subtraction | x - y | x subtract y | -or- | x minus y | |

* | Multiplication | x * y | x multiplied by y | -or- | x times y | |

/ | Division | x / y | x divided by y | |||

% | Modular Division | x % y | x mod y | |||

- | Negation | -x | negative x | |||

++ | Increment | ++x or x++ | increment x | |||

-- | Decrement | --x or x-- | decrement x |

## Description

## Syntax

z = x + y; z = x - y; z = x * y; z = x / y; z = x % y; z = -x; ++x; x++; --x; x--;

## Examples

### Addition

x = 10 + 7; // On integer y = 1.23 + 3.45; // On float p = p + 1; // One pointer and one integer used as a byte offset

### Subtraction

x = 10 - 7; y = 3.45 - 1.23; pointer_c = pointer_a - pointer_b;

Memory pointers can be added and subtracted.

### Multiplication

x = 10 * 7; y = 3.45 * 1.23;

Memory pointers cannot be multiplied or divided.

### Division

x = 10 / 7; y = 3.45 / 1.23;

Integer division of positive values truncates towards zero, so 10/7 is 1.

Memory pointers cannot be multiplied or divided.

### Modular Division

x = 10 % 7;

Modular division returns the remainder produced after performing integer division, so 10%7 is 3.

### Negation

z = -x;

Only provides a negative result if the operand, x, is of a signed data type.