### Quick Quiz #1 - DIV and MOD - Solution

Posted:

**Wed Nov 26, 2014 11:39 am**1. The main issue is one of operator precedence. The monadic - operator has a lower precedence than the multiplicative operators DIV and MOD. Hence:

are equivalent to:

so:

2. However:

is evaluated as:

so in this case:

- Code: Select all
`q := -10 DIV 3;`

r := -10 MOD 3;

are equivalent to:

- Code: Select all
`q := -(10 DIV 3);`

r := -(10 MOD 3);

so:

- Code: Select all
`q = -3`

r = -1

2. However:

- Code: Select all
`x := -10;`

q := x DIV 3;

r := x MOD 3;

is evaluated as:

- Code: Select all
`q := (-10) DIV 3;`

r := (-10) MOD 3;

so in this case:

- Code: Select all
`q = -4`

r = 2