Arithmetic Operands in C++

Except for remainder (%) all other arithmetic operators can accept a mix of integer and real operands. Generally, if both operands are integers then the result
will be an integer. However, if one or both of the operands are reals then the result will be a real (or double to be exact).

When both operands of the division operator (/) are integers then the division is performed as an integer division and not the normal division we are used to.
Integer division always results in an integer outcome (i.e., the result is always rounded down).

For example:

9 / 2 // gives 4, not 4.5!
-9 / 2 // gives -5, not -4!

Advertisement

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.