Friday 4 January 2013

Arithmetic operators ( +, -, *, /, % )

The five arithmetical operations supported by the C++ language are:



Operations of addition, subtraction, multiplication and division literally correspond with their respective
mathematical operators. The only one that you might not be so used to see is modulo; whose operator is the
percentage sign (%). Modulo is the operation that gives the remainder of a division of two values. For example, if
we write:



the variable a will contain the value 2, since 2is the remainder from dividing 11between 3. 


Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=)

When we want to modify the value of a variable by performing an operation on the value currently stored in that
variable we can use compound assignment operators:



and the same for all other operators. For example:


No comments:

Post a Comment