div / mod (integer division and remainder)

Navigation:  Appendices > Macro Language > Operators >

div / mod (integer division and remainder)

Previous pageReturn to chapter overviewNext page

The div operator takes 2 integer expressions and returns an integer value which is the integer division of the first expression by the second. The mod operator returns the remainder left over from the integer division.


This may seem complicated, but it actually mirrors everyday experience, for example when purchasing products or services. Suppose you had $25 and wanted to go to a movie whose entrance price was $10. You would not get 2.5 tickets, you would only get 2 tickets and have $5 remaining.


Using the div and mod operators you would express the above as :


nNumTickets = 25 div 10 // equals 2 tickets

nPocketChange = 25 mod 10 // equals $5 left over


Note that using a value of 0 (zero) on the right side of either of these operators will cause Q++ to generate a run-time error message.

Topic 122300 updated on 22-Feb-2002.
Topic URL: http://www.qppstudio.net/webhelp/index.html?div2.htm