This page is optimized for mobile devices, if you would prefer the desktop version just click here

3.5 Arithmetic operators

An overview of the arithmetic operators within the C++ programming language.

General discussion

An operator performs an action on one or more operands. The common arithmetic operators are:

Action C ++ operator symbol
Addition +
Subtraction -
Multiplication *
Division /
Modulus (associated with integers) %

These arithmetic operators are binary that is they have two operands. The operands may be either constants or variables.

age + 1

This expression consists of one operator (addition) which has two operands. The first is represented by a variable named age and the second is a literal constant. If age had a value of 14 then the expression would evaluate (or be equal to) 15.

These operators work as you have learned them throughout your life with the exception of division and modulus. We normally think of division as resulting in an answer that might have a fractional part (a floating-point data type). However, division when both operands are of the integer data type act differently. Please refer to the supplemental materials on "Integer Division and Modulus".

<< Chapter < Page Page > Chapter >>

Read also:

OpenStax, Programming fundamentals - a modular structured approach using c++. OpenStax CNX. Jan 10, 2013 Download for free at http://cnx.org/content/col10621/1.22
Google Play and the Google Play logo are trademarks of Google Inc.
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use and Privacy Policy.